I have one old script which worked for me in the past :
function make_thumb($img_name,$filename,$thumb_w,$thumb_h)
{
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name);
if(!strcmp("gif",$ext)) $src_img=imagecreatefromgif($img_name);
$old_x=imageSX($src_img); $old_y=imageSY($src_img);
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(!strcmp("png",$ext)) imagepng($dst_img,$filename);
elseif(!strcmp("gif",$ext)) imagegif($dst_img,$filename);
else imagejpeg($dst_img,$filename);
imagedestroy($dst_img); imagedestroy($src_img); }
function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; }
make_thumb(OLD_IMAGE, NEW_IMAGE, NEWWIDTH, NEWHEIGHT); //OLD_IMAGE and NEW_IMAGE are exact file location and names as './img/picture.png'
The last line is the function called to create the image.
Know that this function will resize the ima to exact width/height.
If you need anti blur effect you will need to make a logic calculation inside the function. The second function is for the file extension .. its little stupied but how ever :)
sv3tli0
Junior Poster in Training
83 posts since Aug 2011
Reputation Points: 10
Solved Threads: 18
Skill Endorsements: 0