PHP生产缩略图的问题,我生成的都是黑图

来源:百度知道 编辑:UC知道 时间:2024/05/31 06:06:20
这是源码:<?php
$res=ImageCreateFromJPEG('1.jpeg');
$width=ImageSx($res);
$height=ImageSy($res);
$x=$width/2;
$y=height/2;
$dst=ImageCreateTrueColor(100,100);
ImageCopyResampled($dst,$res,0,0,0,0,$x,$y,$width,$height);
header('Content-Type:image/png');
ImagePNG($dst);
?>
显示的是黑图

给你一个函数,造着用就成了:
<?php
/*
AUTHOR: Yufeng
DATE: 2008-5-4
FUNCTION:Create Smaller Picture
$x 宽 $y 高
*/
function CREATE_SmallImage($path,$imageName,$x,$y){ # 生成缩略图函数
$ImgTypeArr = array("1"=>"gif","2"=>"jpeg","3"=>"png","6"=>"wbmp");
$extent = explode(".",$imageName);
$num = count($extent);
$new_Name = $extent[$num-2]."_thumb.".$extent[$num-1];
if(file_exists($path.$new_Name))
return $path.$new_Name;
else
$image_info = getimagesize($path.$imageName);
$image2_be = "imagecreatefrom".$ImgTypeArr[$image_info[2]];
$image2 = @$image2_be($path.$imageName);
if(!$image2){
return $path.$imageName;
exit;
}
$image1 = imagecreate($x,$y);
$image_x = imageSX($image2);
$image_y = imageSY($image2);
imagecopyresized($image1