Alex Rivera | Logout

Resize/crop/pad a picture to a fixed size

Asked 2009-04-14T11:15:07.917
9

I need to resize a picture to a fixed size. But it has to keep the factors between the width and height.

Say I want to resize a picture from 238 (w) X 182 (h) to 210 / 150

What I do now is:

Original width / target width = 1.333333
Original Height / target Height = 1.213333

Now I take the smallest factor.

Now I always have the right width since 238 / 1.333333 = 210. But the height is still 160.

How do I get the height down to 160 without ruining the pic?

Do I need to crop? If so how?

Edit
Report

1 Answer

2

Just a tip for high-quality fast thumbnail generation from large images: (from the php.net site)

If you do the thumbnail generation in two stages:

  1. From original to an intermediate image with twice the final dimensions, using a fast resize
  2. From the intermediate image to the final thumbnail using a high-quality resample

then this can be much faster; the resize in step 1 is relatively poor quality for its size but has enough extra resolution that in step 2 the quality is decent, and the intermediate image is small enough that the high-quality resample (which works nicely on a 2:1 resize) proceeds very fast.

answered 2009-04-14T14:20:54.227

Your Answer