Home >Backend Development >PHP Tutorial > imagepng的奇怪有关问题

imagepng的奇怪有关问题

WBOY
WBOYOriginal
2016-06-13 13:20:13917browse

imagepng的奇怪问题
代码如下,奇怪的是把imagepng($im)改为imagepng($im,"kk.png")可以得到图片但是直接输出至浏览器就是显示不出来,一直是红叉,这段代码在另一台机器上能正常运行。是我的php配置问题吗?

header("Content-type: image/png");
srand((double)microtime()*1000000);
$login_check_number=strval(rand("11111","99999"));
//$session->setMember("loginCheckNumber", $login_check_number);

$im = imagecreate(50,20) or die ("Cannot Initialize new GD image stream");
$black = ImageColorAllocate($im, 9,142,204);
$foreColor = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
imageline($im, 1, 1, 350, 25, $black);
imagearc($im, 200, 15, 20, 20, 35, 190, $white);
imagestring($im, 5, 7, 3, $login_check_number, $white);
for($i=0 ; $i {
imagesetpixel($im, rand()%50 , rand()%50 , $foreColor);
}

imagepng($im);
imagedestroy($im);
?>


------解决方案--------------------

探讨
引用:
引用:
GD库没开的话imagepng($im,"kk.png")能生成kk.png文件吗?

那应该是和浏览器有关
把第一句换成试试 header("Content-type: image/x-png");


换过也不行
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: PHP 防止远路表单提交 Next article: phpcms2008破绽