Search code examples
phpimageresizeimagick

Stock Image Resize Calculation Ratio Algorithm


I'm working on a project about downloadable stock photos for my client.

They gave me a few example sites to see what they exactly want.

They want options for more than one size like here (XXXL, XXL, XL, L, M, S):

I wonder how is the calculation works for creating different sizes, I think there is no fixed ratio like 1.2, 2, 3 etc.

  • XXXL = 11252W, 3340H
  • XXL = 7381W x 2191H

XXXL and XXL RATIO

11252 / 7381 = 1.52~

How they make a calculation for creating different sizes?


Solution

  • I believe iStockPhoto bases its calculation on print size. For example, as you can read, they sell these formats:

    • S: 272 x 377 px | 17.7 × 5.2" @ 72.0 dpi
    • M: 2544 x 755 px | 8.5 × 2.5" @ 300.0 dpi
    • L: 4070 x 1208 px | 13.6 × 4.0" @ 300.0 dpi
    • ...
    • XXXL: 11252 x 3340 px | 37.5 × 11.1" @ 300.0 dpi

    So, they first get the desired print size (e.g. 17.7" x 5.2"), they specify the print resolution (72 dpi is good for screens; 300dpi is for good quality prints) and eventually they convert that to pixels. The last step is pretty straightforward: if you want 8.5" at 300 dpi (points per inch), assuming that 1 point = 1 pixel (not true with Retina displays, for example, but correct for prints), then you get 8.5 * 300 = 2550 pixel. The resolution should be 2550x750 pixel; the difference could be explained with the fact that the ratio of the image is not exactly 3.4:1.

    Anyways, after you've decided the maximum size, you can resize the photo until it fits. And that's an easy proportion:
    origWidth : origHeight = targetWidth : targetHeight