Many times we need to make thumbnail of the image. The functions which are used for this comes under php GD library, PHP use 'C' library for graphics. PHP is very strong in GD library ...
Here is code to create thumbnail for any image, you have to only pass source of the image, destination where you want to store the thumbnail and desired width of the thumbnail.
//Developed by Dileep
function create_thumb($src,$dest,$setwidth)
{
/* source image */
$source = imagecreatefromjpeg($src);
$width = imagesx($source);
$height = imagesy($source);
/* find the height of this thumbnail, relative to the width */
$setheight = floor($height*($setwidth/$width));
/* creation of new image */
$img = imagecreatetruecolor($setwidth,$setheight);
/* copy source image at a resized size */
imagecopyresized($img,$source,0,0,0,0,$setwidth,$setheight,$width,$height);
/* create the physical thumbnail image to its destination */
imagejpeg($img,$dest);
}
?>
Cheers,
Happy Coding ...
No comments:
Post a Comment