Saturday, 24 August 2013

GD resize image and crop edges

GD resize image and crop edges

Basically if I have a 3400x3400 image and my target size is 340x200 then I
would like to grab the respective 3400x2000 from the middle of the
original image and then scale it down to 340x200, I have a rough idea of
how it will look, here is what I have so far:
$RealWidth=164;
$RealHeight=126;
$org_img = imagecreatefromjpeg($newname);
list($width, $height) = getimagesize($newname);
$ratio2 = $height/$width;
$ratio = $RealHeight/$RealWidth;
$img = imagecreatetruecolor($RealWidth,$RealHeight);
$ims = getimagesize($newname);
imagecopyresized($img,$org_img, 0, 0, 0, 0, $RealWidth, $RealHeight,
$height*$ratio2, $height);
imagejpeg($img,$newname,90);
imagedestroy($img);
I am a bit confused with the math, I also want it to be able to crop a
region from the top/bottom if needed as well.

No comments:

Post a Comment