【问题标题】:GD: php imagepng creates whitespace in imageGD:php imagepng 在图像中创建空白
【发布时间】:2011-06-07 09:29:00
【问题描述】:

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

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

这个文件是用convert创建的,保存在captcha::get_file()的目录中。

而这个文件是用imagecreatefrompng()imagepng()生成的

我对脚本做了一些小改动并制作了一个 gif。但是png还是有问题

这是什么原因造成的,我该如何解决?

这里是phpcode:

<?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);
?>

【问题讨论】:

  • 奇怪,以前从未见过这样的事情。您将需要显示一些我认为的验证码...如果省略content-length 会发生什么?如果使用 gif 等其他格式会怎样?
  • 我尝试了内容长度,但没有任何改变。我会尝试 gif,但它不会解决问题。
  • 这个怎么样:php.net/manual/en/function.imagecreatefrompng.php#90364(使用本色)

标签: php png gd


【解决方案1】:

不是肯定的,但问题可能出在您的内容长度标题中。

header('Content-Length: ' . strlen($image));

此时,在您的代码中,$image 是一种资源数据类型,而不是字符串。尝试简单地删除 content-length 标题行,看看会发生什么。

【讨论】:

  • 以上内容仍然正确。 strlen 用于计算字符串的长度,$image 不是字符串。
猜你喜欢
  • 2014-12-04
  • 2017-01-23
  • 2020-05-02
  • 2018-03-08
  • 1970-01-01
  • 2019-10-31
  • 2012-06-05
  • 2011-08-29
  • 2023-03-31
相关资源
最近更新 更多