dongzhukuai8177 2017-03-19 04:05
浏览 71

PHP动态图像无法正常显示

I just moved a site to a new server running PHP 7. It was originally on PHP 5.4, I believe. The following URL should display an image with a code in it, like a captcha:

http://appreviewhelper.com/static/captcha/GkK9yEiaw6

When that URL is hit, the following code is ran:

$code=rand(1000,9999);
$code = (string)$code;
$_SESSION["code"]=$code;

$im = imagecreate(50, 24);
$bg = imagecolorallocate($im, 238, 238, 238); //background color blue
$fg = imagecolorallocate($im, 85, 85, 85);//text color white
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 5, 5,  $code, $fg);

header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
header("Content-Disposition: inline; filename=captcha.png");
imagepng($im);

imagedestroy($im);

exit();

It was working fine on the old server. I've made sure the PHP GD library is installed and the module has been enabled, and I've verified that over and over... but, still I just get a small, blank image. Any ideas?

Thanks

Edit: Below is output from gd_info() from this site:

    array(12) {
  ["GD Version"]=>
  string(5) "2.1.1"
  ["FreeType Support"]=>
  bool(true)
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(true)
  ["XBM Support"]=>
  bool(true)
  ["WebP Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)
}
  • 写回答

1条回答 默认 最新

  • dprntkxh703029 2017-03-20 02:25
    关注

    I'm answering myself because, after hours and hours, I found the problem. The client shared the files with me using Dropbox. Apparently, Dropbox converted the files to Unicode. So, the file which had the image generation code was sending a BOM before the image was output, causing the image to look corrupt. Changing the encoding of the file to UTF-8 fixed the issue...

    Thanks for the time of those who viewed and responded.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗