shortysbest Posted July 27, 2011 Share Posted July 27, 2011 How can i make this crop the image so it's not distorted? function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } Quote Link to comment https://forums.phpfreaks.com/topic/242995-resize-image-to-heightwidth-and-crop-so-its-not-distorted/ Share on other sites More sharing options...
xyph Posted July 27, 2011 Share Posted July 27, 2011 Perhaps a little math is in order? Find out which dimension you want to use as your reference. Do you want all widths to be 300px? Do you want all heights to be 600px? Do you want to find out which is bigger and base it off that? Once you find which dimension you want to use as a reference (let's use width for example), you can simply divide to find the ratio. new width / original width = ratio original height * ratio = new height. So, you have an image that's 1024x768. You want the width to be 300, so 300 / 1024 = 0.2929... 768 * 0.2929 = 225 Your new image is 300 x 225 Quote Link to comment https://forums.phpfreaks.com/topic/242995-resize-image-to-heightwidth-and-crop-so-its-not-distorted/#findComment-1248050 Share on other sites More sharing options...
shortysbest Posted July 27, 2011 Author Share Posted July 27, 2011 Well not exactly how I want, I don't know how to crop an image, I've never really worked with php image techniques, perhaps I should begin. What i am looking for is to take an image, say 1280x800 and crop it to let's say 50x50. I don't want to just simply change the size from 1280x800 to 50x50, I want to crop it so it's not distorted Quote Link to comment https://forums.phpfreaks.com/topic/242995-resize-image-to-heightwidth-and-crop-so-its-not-distorted/#findComment-1248053 Share on other sites More sharing options...
xyph Posted July 27, 2011 Share Posted July 27, 2011 Oh, I see. http://www.talkphp.com/advanced-php-programming/1709-cropping-images-using-php.html Pretty much sums it up. Quote Link to comment https://forums.phpfreaks.com/topic/242995-resize-image-to-heightwidth-and-crop-so-its-not-distorted/#findComment-1248057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.