# How to count DPI of an image (challenge)?

a) I have used an online service where you can upload an image.

b) Afterwards, you can select a print size and it gives you information on what is actual DPI based on that print size.

c) When it gives you information if that particular DPI (dots per inch) for that print size is enough quality to print, so basically it outputs "bad", "average" or "good".

I want to built this functionality on my own site, but I lack logic's behind how they count DPI.

This is my two tests where I upload slightly different photos. As site outputs DPI it is easy to try to get how it counts it, but as for different photos it does differently. I just can not grasp the pattern on why it does so.

Here is my two different photos uploaded:

Product: Poster Size: 1000x1200

I will just explain the first value - 8x10 -> 1200 / 10 - you get DPI by subtracting photo height with print size height.

8x10 -> 1200 / 10   ->>> why this DPI is counted differently from other image?
10x10 -> 1000 / 10
12x12 -> 1000 / 12
12x16 -> 1200 / 16  ->>> why this DPI is counted differently from other image?
14x14 -> 1000 / 14
16x16 -> 1000 / 16
12x18 -> 1200 / 18
18x18 -> 1000 / 18
16x20 -> 1200 / 20  ->>> why this DPI is counted differently from other image?
18x24 -> 1200 / 24  ->>> why this DPI is counted differently from other image?
24x36 -> 1200 / 36


Product: Poster Size: 1000x1333

8x10 -> 1000 / 8    ->>> comparing to this value
10x10 -> 1000 / 10
12x12 -> 1000 / 12
12x16 -> 1000 / 12  ->>> comparing to this value
14x14 -> 1000 / 14
16x16 -> 1000 / 16
12x18 -> 1333 / 18
18x18 -> 1000 / 18
16x20 -> 1000 / 20  ->>> comparing to this value
18x24 -> 1000 / 18  ->>> comparing to this value
24x36 -> 1333 / 36


Just do not get it why for a very similar image, counting of the same print sizes are different for particular values?

Any ideas?

• Usually the printer will tell you the minimum DPI required. I believe that most printers use 300 DPI for printing photos. They may let you get away with less (hence the bad and average categories), but their hardware prints at 300 dpi so your image should have enough pixels for that. – user1118321 Mar 7 '17 at 5:39
• Keep in mind that those suggestions are mostly useless. You won't see anywhere near 300 DPI from common commercial printers on typical photo paper. It's closer to 100-150 DPI in my experience. And you won't be able to see even that much on larger prints from a reasonable viewing distance so you can get away with less. – Olivier Mar 8 '17 at 20:53

They are not "very similar images". They have quite different aspect ratios. The first one has a 5:6 aspect ratio, while the other has a 3:4 ratio.

If you try to print a 5:6 image at 8x10, what you find is that if the width is 8, then a 5:6 image would have a height of 9.6, which is less than 10. So that means the 5:6 image can fit into the 8x10 region with its full width; some of the height will go unused.

However, a 3:4 aspect ratio image at 8x10 doesn't do that. If the width is 8, then the 3:4 aspect ratio would require a height of 10.6. That would exceed the maximum available height, so the width cannot be full width. Instead, it uses the full height of 10, and the width used will only be 7.5.

You will find that this is the case for all of the ones where you noted such a difference.

The "DPI" its computing is essentially the number of pixels in the dimension that isn't the maximum. For the 3:4 image at 8x10, it takes the image width (1000) and divides by the area width (8). For the 5:6 image at 8x10, it takes the image height (1200) and divided by the area height (10).

This number only makes sense if we assume that the image is being scaled independently in width and height to fit the page. That is, the aspect ratio of the image is not being preserved when printed. So a 5:6 image is being transformed into a 4:5 aspect ratio image when printed at 8x10.

Since each dimension is being scaled differently, each dimension has its own DPI. The lowest DPI will be for the dimension being stretched the most. And that's what this formula seems to be computing.

Of course... who cares? Stretching images creates obvious visual distortion, and should pretty much never be done when printing something you actually want to have a paper copy of. So I would declare this computation algorithm to be bogus and move to something that actually makes sense with a reasonable printing methodology.

• One more question - how did you count aspect ratio of these images? – funguy Mar 7 '17 at 22:27
• For real, @Nicol Bolas, how did you determine that 1000x1333 image has aspect ratio of 3:4? Even this site ninjaunits.com/calculators/aspect-ratio does not determine this. – funguy Mar 11 '17 at 17:59
• @funguy: The aspect ratio of an image is the ratio of the image's width to its height. You don't need a website to divide 1000 by 1333; you only need a calculator. Note that this ratio is just the ratio of the image itself; some image formats have metadata that specify what aspect ratio the image should be stretched to in order to correctly reproduce what it stores. But absent such metadata, the assumption is that the ratio of the pixels is how the image should be displayed. – Nicol Bolas Mar 11 '17 at 18:04
• Yes, @Nicol Bolas, but this is what I want to understand, how to find out aspect ratio with a calculator. If you divide 1000/1333 you will get something like 0.75018... but still, how to add up this final result - 3x4? – funguy Mar 11 '17 at 19:26