Results 1 to 1 of 1
Jul 14, 2009, 06:49 #1
- Join Date
- Jul 2009
- 0 Post(s)
- 0 Thread(s)
thumnail + proportional image crop
My clients ask if its possible to crop the images that where uploaded to a fixed
size, in this case 118x79
now he had landscape images, squares and portraits.
The code below is nearly perfect, its just that it always shows a little border when the orignal image isn't a standard crop; fe wideangle's, squares
or with squares the y axis isn't working out. it does work with portrait images though.
Basically whats needed is a script that crops the image so it always fit 118x79 disregarding what the original size was. and centering the image so no borders are shown.
any insights on this code ? a big big thanks in advance. its driving me bonkers atm.
$width = 118;
$height = 79;
list($width_orig, $height_orig) = getimagesize($upload_image);
$ox = $width_orig;
$oy = $height_orig;
$nx = 118;
$th = 79;
$ny = floor($oy * ($nx / $ox));
// height * (thumbwidth / width)
$thumb = imagecreatetruecolor($nx, $th);
$source = imagecreatefromjpeg($upload_image);
imagecopyresampled($thumb, $source, 0, $th / 2 - ($ny / 2), 0, (-$ny / 2), $nx, $ny, $width_orig, $height_orig);