Published in: PHP
<?php /* ImageThumb - Creates a thumbnail image from another based on specified sizes SourceImage - The location of the image in which you want to resize DestImage - The location to save the thumb, use null if you want to just display to browser Width - The resized width of the image Height - The resized height of the image Type - The image type in which you want to save Note: The thumb is resized while keeping the aspect ratio, so width and height are not the absolute width and height. */ function ImageThumb($sourceImage, $destImage, $width, $height, $type = "png") { if($imageSize[0] > $imageSize[1]) { $newWidth = $width; $newHeight = $imageSize[1] * ($newWidth / $imageSize[0]); } else { $newHeight = $height; $newWidth = $imageSize[0] * ($newHeight / $imageSize[1]); } case "image/jpeg": $image = imagecreatefromjpeg($sourceImage); break; case "image/gif": $image = imagecreatefromgif($sourceImage); break; case "image/png": $image = imagecreatefrompng($sourceImage); break; default: echo "The file type {$t} is not supported, please use either jpeg, gif, or png"; break; } $thumb = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $newWidth, $newHeight, $imageSize[0], $imageSize[1]); switch($type) { case "jpg": case "jpeg": imagejpeg($thumb, $destImage); break; case "gif": imagegif($thumb, $destImage); break; case "png": imagepng($thumb, $destImage); break; default: "The image type {$type} is not supported, please choose another."; break; } imagedestroy($image); imagedestroy($thumb); } ?>
Comments
Subscribe to comments
You need to login to post a comment.

Nice, for all the users watch this script how can make a thumb of every kind of image jpg/gif/png.