Resize then crop PHP
Ok, basically I want all images to be 170x170px squares. Thus if an image is not a square i want it to be resized, and then cropped in the middle.. I have spent numerous hours playing with this and I am getting nowhere.. I have gotten it to crop a section of the bigger image etc, but i specifically need the image to be resized, then cropped.. Any help would be greatly appreciated. // get image size of img $x = @getimagesize($img); // image width $sw = $x[0]; // image height $sh = $x[1]; if($sw > $sh) // Horizontal Rectangle? { $newwidth = ($sw/$sh)*170; $newheight=170; $x_pos = ($sw - $sh) / 2