I need to first resize an image proportionally (the width is the important dimension) and then crop afterwards to chop of any excess height and then store the new version in a directory.
I’ve managed to do the resizing fine and I end up with images that are the correct width in my directory. Somehwere in here I need to crop the excess height off. But I can’t work out where I need to do it. Do I need to use copyimageresampled somehow. I want to crop all images so they’re 50px in height.
Here’s what I have so far fo the resizing:
$src = ImageCreateFromJpeg($upfile);
$dst = ImageCreateTrueColor($tn_width, $tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImageJpeg($dst, 'images/' . $_FILES['image']['name']);
This is what I was after. A 2 stage process. The trick is to resize the image in to a temporary image and then crop it:
http://salman-w.blogspot.com/2009/04/crop-to-fit-image-using-aspphp.html