bsilewicz Posted March 26, 2009 Share Posted March 26, 2009 I need to 2 things - one, crop an image to either 640px width max or 600px height max - thats no problem. The second is starting to annoy me. I want to create a canvas that is 640px (w) x 600px (h) and center the cropped image on this canvas. I was trying to use 'imagefill' - any thoughts?? function Crop($src, $dest, $new) { $img = null; $info = pathinfo($src); list($width, $height) = getimagesize($src); if ($width > $height) { $ss = $height; $ys = 0; $xs = ceil(($width - $height) / 2); }else{ $ss = $width; $ys = ceil(($height - $width) / 2); $xs = 0; } $temp = imagecreatetruecolor($new[0], $new[1]); $cl = imagecolorallocate($temp, 0, 0, 0); imagefill($temp, 0, 0, $cl); switch (strtolower($info['extension'])) { case "jpg": $img = imagecreatefromjpeg($src); imagecopyresampled($temp, $img, 1, 1, $xs, $ys, $new[0]-2, $new[1]-2, $ss, $ss); imagejpeg($temp, $dest, 100); break; case "gif": $img = imagecreatefromgif($src); imagecopyresampled($temp, $img, 1, 1, $xs, $ys, $new[0]-2, $new[1]-2, $ss, $ss); imagegif($temp, $dest); break; case "png": $img = imagecreatefrompng($src); imagecopyresampled($temp, $img, 1, 1, $xs, $ys, $new[0]-2, $new[1]-2, $ss, $ss); imagepng($temp, $dest); break; } imagedestroy($temp); imagedestroy($img); } Link to comment https://forums.phpfreaks.com/topic/151183-image-manipulation/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.