用GD生成缩略图
时间:2005-12-01 来源:yejr
生成的图片质量还行。。。
$newImg = 'image.jpg';
@header("Content-type: image/jpeg");
//gif
if(1 == $type)
{
$srcimg = @imagecreatefromgif($newImg);
}
//jpg
elseif (2 == $type)
{
$srcimg = @imagecreatefromjpeg($newImg);
}
else
{
return false;
}
//$zoomImg = @imageCreate($dstW,$dstH);
$zoomFile= 'zoom_image.jpg';
//@ImageCopyResized($zoomImg, $srcimg,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
if(function_exists("imagecopyresampled"))
{
$zoomImg = @imagecreatetruecolor($dstW, $dstH);
@imagecopyresampled($zoomImg, $srcimg, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
}
else
{
$zoomImg = @imagecreate($dstW, $dstH);
@imagecopyresized($zoomImg, $srcimg, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
}
//gif
if(1 == $type)
{
@ImageJpeg($zoomImg, $zoomFile);
}
//jpg
elseif (2 == $type)
{
@ImageJpeg($zoomImg, $zoomFile);
}
else
{
die("alert('上传的文件格式只能为GIF/JPG 2种!!!'); history.go(-1);");
}
@ImageDestroy($zoomImg);
$newImg = 'image.jpg';
@header("Content-type: image/jpeg");
//gif
if(1 == $type)
{
$srcimg = @imagecreatefromgif($newImg);
}
//jpg
elseif (2 == $type)
{
$srcimg = @imagecreatefromjpeg($newImg);
}
else
{
return false;
}
//$zoomImg = @imageCreate($dstW,$dstH);
$zoomFile= 'zoom_image.jpg';
//@ImageCopyResized($zoomImg, $srcimg,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
if(function_exists("imagecopyresampled"))
{
$zoomImg = @imagecreatetruecolor($dstW, $dstH);
@imagecopyresampled($zoomImg, $srcimg, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
}
else
{
$zoomImg = @imagecreate($dstW, $dstH);
@imagecopyresized($zoomImg, $srcimg, 0, 0, 0, 0, $dstW, $dstH, $srcW, $srcH);
}
//gif
if(1 == $type)
{
@ImageJpeg($zoomImg, $zoomFile);
}
//jpg
elseif (2 == $type)
{
@ImageJpeg($zoomImg, $zoomFile);
}
else
{
die("alert('上传的文件格式只能为GIF/JPG 2种!!!'); history.go(-1);");
}
@ImageDestroy($zoomImg);
相关阅读 更多 +