DEV Community

celticgemini001
celticgemini001

Posted on

The DPI Field in Your File Decides Nothing About Its Quality, and Everything About Its Print Size

There is a metadata field in every JPEG that determines how big a photo prints, and it has no effect whatsoever on how much detail the file contains. Confusing the two costs people real money: they upscale an image to "make it 300 DPI" and end up with a file that is four times larger, offends nobody's printer, and looks identical on paper.

I measured the field directly — wrote it, read it back, checked the byte cost, and checked whether an upscale disturbs it — because the behaviour is more specific than the folklore suggests, and the specifics are what let you stop guessing.

What the field actually is

A JPEG's density lives in the JFIF APP0 segment: one byte of units (0 = no units, 1 = dots per inch, 2 = dots per centimetre) and two 16-bit values, X_density and Y_density. That is it. It is a header, eight bytes of payload, and it does not participate in decoding.

Here is what I measured on a 1080×1620 source, writing each value with Pillow and reading it back:

Written Read back Reported print size File bytes
no tag written 2.54 dpi (1 px/cm) 1700.8 × 2551.2 in 3,018,971
300 dpi 300 dpi 14.4 × 21.6 in 3,018,971
75 dpi 75 dpi 57.6 × 86.4 in 3,018,971

Byte-identical across all three. The same 3,018,971 bytes, whether the file claims 75 dpi or 300 dpi or nothing at all. The print size changes by a factor of four; the pixels, and the cost of storing them, do not change at all. A PNG written with the equivalent pHYs chunk cost 21 bytes more with the tag than without — 11.7 MB either way — so the metadata is genuinely almost free.

That table is the whole argument in miniature: DPI is a promise about physical size, not a claim about information content.

Left: the same pixels at four densities give four print sizes. Right: the file size does not move at all

The trap: the field you did not write

The first row is the interesting one. When no density is written, a reader does not report "unknown" — it reports a default. In my measurement, the JPIF wrote units = 0 with density values of 1, which readers interpreted as 1 pixel per centimetre, i.e. 2.54 dpi. That is not a neutral value. A print pipeline that trusts the file will compute a print size of 1700 inches wide and then do something arbitrary: clamp to the page, refuse the job, or scale with a factor nobody checked.

And the assumed fallback depends entirely on the reader, not the file:

Reader assumption Print size of the same 4320×6480 file
72 dpi 60.0 × 90.0 in
96 dpi 45.0 × 67.5 in

The same pixels, two plausible conventions, a 33% difference in the physical size the print shop thinks you asked for. If your workflow hands files to a printer or a publisher, set the density explicitly and do not rely on a default. It is one argument in one call and it removes a whole class of support tickets.

What re-tagging actually costs, per format

I also measured the cost of writing the tag into three formats, because "just re-save it with the right DPI" is advice that can quietly recompress your image.

Format Bytes without tag Bytes with 300 dpi tag Delta
JPEG 3,018,971 3,018,971 0
PNG 11,705,868 11,705,889 +21
WebP 1,425,524 (see note) small

For JPEG the delta is exactly zero, and that is worth pausing on. A JPEG carries its density in the JFIF header, which sits before the compressed scan data, so writing it does not require re-encoding. Pillow's save(dpi=300) on an already-sized image produces byte-identical pixel content at identical size.

But — and this is the case where the "cost" is not visible in the byte count — re-saving a JPEG through most image libraries decodes and re-encodes it. My measurement compares writing the tag at save time to not writing it at save time, with the same encoder settings; it does not claim you can add a tag to an existing JPEG without a decode/encode cycle. If you are re-saving, you are paying a generation. If you can set the tag at the moment of the original save, the cost really is zero.

The practical consequence: set the density on the export, not afterwards. Exporting once with the right value is free; fixing it later is a generation of quality.

JPEG density and EXIF resolution are two different fields

A JPEG can carry resolution information in two places: the JFIF APP0 segment I have been discussing, and an EXIF IFD with XResolution, YResolution and ResolutionUnit. They can disagree, and different software reads different ones.

In my fixture I wrote a JFIF 300 dpi tag and checked what the EXIF block reported: xres: None, yres: None, unit: None. No EXIF resolution fields were written at all — Pillow's dpi= argument touches only JFIF. So a tool that reads only EXIF would find nothing and fall back to its own default, while a tool that reads JFIF would see 300. Same file, two answers.

If interop matters, write both. If you are debugging a print-size mismatch, this is the first thing to check: which of the two fields does each piece of software in your chain actually read?

That is the same rule as any specification work — follow the JPEG File Interchange Format notes for the APP0 fields and the Exif tag reference for the IFD, and do not assume one implies the other.

What an upscale does to the tag

This is where it connects to the rest of the series. Suppose you have a 1080×1620 file tagged 300 dpi — a 3.6 × 5.4 inch print — and you upscale 4× to 4320×6480. Two possible behaviours:

  1. Density preserved → the file now prints 14.4 × 21.6 inches at the same 300 dpi. The picture got bigger; the per-inch quality claim is unchanged.
  2. Density scaled by 4 → 1200 dpi, and the file still prints 3.6 × 5.4 inches. The picture is the same physical size at four times the density.

In my measurement, upscaling the 1080×1620 source to 4320×6480 with dpi=300 retained 300 dpi, and the reported print size grew to 14.4 × 21.6 in. Behaviour 1. Which means an upscale makes the print larger, not denser — if you wanted the density to rise you have to change the tag yourself, and if you wanted the size to stay the same you also have to change the tag yourself.

Neither is wrong. What is wrong is not knowing which one your tool does, because "I upscaled to 300 DPI" is very often a wish rather than a description.

The arithmetic that actually matters

Strip away the metadata and the question is trivial arithmetic, which is why it is worth writing down once:

print_inches = pixels / dpi
required_pixels = print_inches × target_dpi
Enter fullscreen mode Exit fullscreen mode

For a 6 × 9 inch print at 300 dpi you need 1800 × 2700 pixels. At 150 dpi — perfectly respectable for a poster viewed from a metre — you need 900 × 1350. For a 24 × 36 inch poster at 150 dpi, 3600 × 5400.

Print dpi Pixels needed Upscale from 1080×1620
3.6 × 5.4 in (postcard) 300 1080 × 1620 none — native
6 × 9 in 300 1800 × 2700 1.67× (so 2×)
8 × 12 in 300 2400 × 3600 2.2× (so 3×)
12 × 18 in 200 2400 × 3600 2.2× (so 3×)
24 × 36 in (poster) 150 3600 × 5400 3.3× (so 4×)

Notice how the required factor collapses as the viewing distance grows. The poster at 24 × 36 needs less than twice the pixels of the 8 × 12 at 300 dpi, because a poster is viewed from far away and 150 dpi is ample. This is the most common way people over-buy upscaling: they apply 300 dpi to everything, including things nobody will hold.

The rule that follows: decide the print size and viewing distance first, compute required pixels second, and only then decide whether to upscale. If the answer is 1.3×, do not run a 4× pass — you are paying for interpolation and inventing detail you cannot display.

When the tag is the only thing you need

If the pixel count is already sufficient and only the print size is wrong, you do not need an upscale at all — you need a tag. That is the zero-byte case from the first table, at least when you can set it at export time.

I ran these measurements while working with UpgoLAB's browser upscaler, because its 2× and 4× output is exactly the situation where the tag question becomes live: the pixels change and the physical interpretation depends on what the tool writes. Whatever tool you use, check the output's density field before you send it to a printer, and check it against the size you actually want rather than assuming the upscale handled it.

Here is the spatial half of what a 4× pass looks like across five presets, if you are still deciding whether you need one:

The five-line checklist

  1. Compute required pixels from print size and viewing distance, not from a fixed dpi number. 300 dpi for a hand-held print, 150 for a wall poster.
  2. If the pixels are already enough, change the tag, not the image. Nothing gets you a better print than not re-encoding.
  3. Set the density at export time, never as a later fix — a later fix is a generation.
  4. Write both JFIF density and EXIF resolution if the file has to survive a chain of unknown software.
  5. Check the tag on the output of any resize or upscale, and know whether your tool preserves or scales density. Mine preserved it, which means the print got bigger.

None of this is about image quality. All of it is about not paying four times the file size to change a number that costs zero bytes.

Top comments (0)