gpt4 book ai didi

php - GD:php imagepng 在图像中创建空白

转载 作者:可可西里 更新时间:2023-10-31 23:50:28 26 4
gpt4 key购买 nike

当我用 php 创建图像时,我遇到了一些 GD 问题。

奇怪的是,它可以在一台装有 5.3.1 版 php 的服务器上运行,但不能在 5.2.14 版 php 上运行。 (我不确定是 php 版本还是 GD lib 这样做。)

alt text此文件使用 convert 创建并保存在 captcha::get_file() 的目录中。

alt text这个文件是用 imagecreatefrompng()imagepng()

生成的

alt text我对脚本做了一些小改动并制作了一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com