| 0 comments ]

The following function will help you to create a thumbnail for an image.

function get_thumb($img_filename, $maxwidth, $maxheight) {

$img_size = getimagesize($img_filename) ;

if($img_size) {

$width = $img_size [0];

$height = $img_size [1];

$thumb_height=$ height;

$thumb_width=$width;

if ($width > $maxwidth) {

$thumb_width = $maxwidth;

$thumb_height = floor($height * ($maxwidth / $width));

}

if ($thumb_height > $maxheight) {

$thumb_width = floor($thumb_width * ($maxheight / $thumb_height));

$thumb_height = $maxheight;

}

if ( (imgsizearray['mime']== 'image/jpeg')|| (imgsizearray['mime']== 'image/png')|| (imgsizearray['mime']== 'image/gif')) {

$type=explode('/', $imgsizearray['mime']);

$thumb_image = imagecreatetruecolor($thumb_width, $thumb_height);

$image ="imagecreatefrom" . $type[1] ($img_filename);

if($image){


/*Copy and resize part of an image with resampling*/

imagecopyresampled($thumb_image, $image, 0,0,0,0,$thumb_width,$thumb_height,$width,$height);

}

imagejpeg($thumb_image, null, 100);

}

}

return false;

}

you can call the function like this . get_thumb ($file,100,100);

$img_filename is the uploaded file,and $maxwidth and $maxheight are the height and width specification for thumb

0 comments

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.