Jump to content

resize image to height/width and crop so it's not distorted?


shortysbest

Recommended Posts

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;
   }

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.