Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.