PHP GD-空盒 [英] PHP GD - Empty box
问题描述
经过一段时间的搜索,似乎无法解决这个问题.我(尝试)学习php-gd,但是出于某种原因,无论出于什么原因,即使使用现成的代码段,运行文件时我所得到的只是一个很小的框(可能是20x20px的框,带有纯边框) .通过phpinfo()查看;并且gd运行正常,我似乎找不到代码中的任何错误,任何想法?
Been searching for a while and can't seem to get through this. I'm (attempting) to learn php-gd, but for some reason no matter what, even by using ready-to-go code snippets, all I get when the file is run is a small, maybe 20x20px box with a plain border. Looked through phpinfo(); and gd is running fine, and I can't seem to find any errors with the code, any ideas??
<?php
$redimg = imagecreatetruecolor(100, 100);
$image = imagecreatefrompng('overlay.png');
// sets background to red
$red = imagecolorallocate($redimg, 255, 0, 0);
imagefill($redimg, 0, 0, $red);
imagecopymerge($image, $redimg, 0, 0, 0, 0, 100, 100, 75);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
imagedestroy($redimg);
?>
推荐答案
您看到的是空白正方形,因为由于Content-Type标头而有一个错误被抑制.尝试删除标题以查看错误是什么,或者查看错误日志.
You're seeing that blank square because there's an error that's being suppressed due to the Content-Type header. Try removing the header to see what the error is, or look in your error log.
此外,如果您正在学习PHP/GD,我建议您看一下我编写的库,该库有效地将许多GDs函数包装到一个更加用户友好的API中:
Also, if you're learning PHP/GD I'd recommend taking a look into a library I wrote that effectively wraps many of GDs functions into a more user-friendly API: SimpleImage
该库可以为您节省大量时间,代码和眼泪.
This library can save you a lot of time, code, and tears.
这篇关于PHP GD-空盒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!