当我用 php 创建图像时,我遇到了一些 GD 问题。
奇怪的是,它可以在一台装有 5.3.1 版 php 的服务器上运行,但不能在 5.2.14 版 php 上运行。 (我不确定是 php 版本还是 GD lib 这样做。)
此文件使用 convert 创建并保存在 captcha::get_file()
的目录中。
这个文件是用 imagecreatefrompng()
和 imagepng()
我对脚本做了一些小改动并制作了一个 gif。但是png还是有问题
是什么原因造成的,我该如何解决?
这是 php 代码:
<?php
session_start();
require_once("./captcha.php"));
// creates the image with convert and returns the location of the picture
// document_root/picture/picture.png
$picloc = captcha::get_file();
$image = @imagecreatefrompng($picloc);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
unlink($picloc);
?>
最佳答案
不是肯定的,但问题可能出在您的内容长度 header 中。
header('Content-Length: ' . strlen($image));
此时在您的代码中,$image 是资源数据类型,而不是字符串。尝试简单地删除内容长度标题行,看看会发生什么。
关于php - GD:php imagepng 在图像中创建空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4661673/