Slide 30
Slide 30 text
Thumbnailing Images – GD
Create a scaled, centered, cropped, 200x200 thumbnail
[startup]
if($imgw > $imgh)
list($nw,$nh) = bob_magic_proportion_func($imgw,$imgh,-1,200);
else
list($nw,$nh) = bob_magic_proportion_func($imgw,$imgh,200,-1);
// scale it down to the calculated size.
$new = imagecreatetruecolor($nw,$nh);
imagecopyresampled($new,$img,0,0,0,0,$nw,$nh,$imgw,$imgh);
imagedestroy($img); unset($img);
// crop off the excess from either end to center it and fit it
$last = imagecreatetruecolor(200,200);
imagecopyresampled(
$last, $new,
0, 0,
($nw / 2) – (200 / 2), ($nh / 2) – (200 / 2),
200, 200, 200, 200
);
imagedestroy($new); unset($new);
$img = $last; unset($last);
[shutdown]