使用GD输出黑色图像调整大小
什么会导致php gd在调整大小后产生黑色图像?以下代码始终为每个有效的 jpeg 文件输出一个黑色图像。
<?php
$filename = 'test.jpg';
$percent = 0.5;
header('Content-Type: image/jpeg');
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb);
imagedestroy($thumb);
?>
输出 :gd_info()
Array
(
[GD Version] => bundled (2.1.0 compatible)
[FreeType Support] => 1
[FreeType Linkage] => with freetype
[T1Lib Support] =>
[GIF Read Support] => 1
[GIF Create Support] => 1
[JPEG Support] => 1
[PNG Support] => 1
[WBMP Support] => 1
[XPM Support] =>
[XBM Support] => 1
[JIS-mapped Japanese Font Support] =>
)
该代码似乎在其他环境中工作。可能与操作系统,已安装的软件包,库等有关?