OK i thought i understood this function but i have a complete mental block on this one.
I wanted to create cropped thumbnails of size 75x75 from photos that are 800x536.
the imagecopyresampled function has 10 possible parameters. i first tried this:
// Starting point of crop
$tlx = floor(($width / 2) - ($new_width / 2)); //finds halfway point of big image and subtracts half of thumb.
$tly = floor(($height / 2) - ($new_height / 2)); //gets centre of image to be cropped.
imagecopyresampled($tmp_img,$img,0,0,$tlx,$tly,$new_width,$new_height,$orig_width,$orig_height);
this finds either side of the halfway mark on the large image and crops it out. or so i thought. but it actuall crops a bit of the picture and leaves the right hand side and bottom in black (presumably from the imagecreatetruecolor earlier.
so i found a way to do what i want but i want you to explain how it is working.
i now have:
//Create thumbnails.
$new_width = 75; //pixels.
$new_height = 75;
if($width > $height) $biggest_side = $width;
else $biggest_side = $height;
//The crop size will be half that of the largest side
$crop_percent = .5;
$crop_width = $biggest_side*$crop_percent;
$crop_height = $biggest_side*$crop_percent;
$c1 = array("x"=>($width-$crop_width)/2, "y"=>($height-$crop_height)/2);
//Create new image with new dimensions to hold thumb
$tmp_img = imagecreatetruecolor($new_width,$new_height);
//Copy and resample original image into new image.
imagecopyresampled($tmp_img,$img,0,0,$c1['x'],$c1['y'],$new_width,$new_height,$crop_width,$crop_height);
it's doing it perfectly, shrinking the image and then cropping out the middle, but my maths isn't very sharp and also i think it's definitely that i don't fully understand the imagecopyresampled function.
can someone walk me through it? parameter by parameter. especially the last two. originally i entered the width and height of the original image, but this enters 400 and 400 (half of the longest side). sorry for the rant. hope my mind understands this soon :)
Alex