简体   繁体   English

创建png,jpg和gif图像的缩略图创建

[英]create thumbnail creation of png,jpg, and gif images

I am developing a php web site. 我正在开发一个php网站。 Here I need to create thumbnail of jpg, png and gif images 在这里,我需要创建jpg,png和gif图像的缩略图

See my current code 查看我当前的代码

if (@$fileType=="image/gif")
{
$im=ImageCreateFromGIF($add);
$width=ImageSx($im);              // Original picture width is stored
$height=ImageSy($im);                  // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
Header("Content-type: image/gif");
ImageGIF($newimage,$tsrc);
}
elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}
chmod("$tsrc",0777);
}////////// end of gif file thumb nail creation//////////


////////////// starting of JPG thumb nail creation//////////
if($fileType=="image/jpeg" or $fileType=="image/jpg"){
$im=ImageCreateFromJPEG($add); 
$width=ImageSx($im);              // Original picture width is stored
$height=ImageSy($im);             // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);                 
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
chmod("$tsrc",0777);
}

Here I need to create thumbnail of png images. 在这里,我需要创建png图像的缩略图。 But I don't know how? 但我不知道怎么办?

I sit possible to add thumbnail creation of png image within the existing code? 我可以在现有代码中添加png图像的缩略图创建吗?

Does anyone know? 有人知道吗?

Please rely 请依靠

You can do the same thing as in JPEG thumbnail creation part but change JPEG to PNG instead. 您可以执行与JPEG缩略图创建部分相同的操作,但改为将JPEG更改为PNG。

if($fileType=="image/png"){
   $im=ImageCreateFromPNG($add); 
   $width=ImageSx($im);              // Original picture width is stored
   $height=ImageSy($im);             // Original picture height is stored
   $newimage=imagecreatetruecolor($n_width,$n_height);                 
   imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
   ImagePng($newimage,$tsrc);
   chmod("$tsrc",0777);
}

Also, please look at the PHP manual http://www.php.net/manual/en/ref.image.php for any other formats. 另外,请查看PHP手册http://www.php.net/manual/en/ref.image.php以获取任何其他格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM