user1263260
user1263260

Reputation: 243

create thumbnail creation of png,jpg, and gif images

I am developing a php web site. Here I need to create thumbnail of jpg, png and gif images

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. But I don't know how?

I sit possible to add thumbnail creation of png image within the existing code?

Does anyone know?

Please rely

Upvotes: 0

Views: 7735

Answers (1)

chalet16
chalet16

Reputation: 187

You can do the same thing as in JPEG thumbnail creation part but change JPEG to PNG instead.

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.

Upvotes: 2

Related Questions