测试如下代码
<?php
$sourceImage = 'images/1.jpg';
$width = 200;
$height = 200;
$original = imagecreatefromjpeg($sourceImage);
$dims = getimagesize($sourceImage);
echo $dims[0]." ".dims[1];
$image = imagecreatetruecolor($width, $height);
//$bgcolor = imagecolorallocate($image, 255,255,255);
//imagefill($image,0,0,$bgcolor);
//生成缩略图
imagecopyresampled($image, $original, 0, 0, 0, 0, $width, $height, $dims[0], $dims[1]);
header("content-type:image/jpeg");
imagejpeg($image);
imagedestroy($image);
发现图片显示不出来。
原因为:在图像输出前不能有任何打印把调试的echo输出去掉就好了。