Sub topic 4
Resolution, pixel dimensions and PPI/DPI
This chapter assumes you know what a pixel is, that raster images are grids of pixels, and that files have extensions such as .jpg and .png. It covers the three numbers people often mix up when they say "resolution".
Three different things called "resolution"
People use "resolution" loosely. Three separate ideas hide behind it:
- Pixel dimensions are the width and height of the image in pixels, such as 1920 × 1080. This is a fact about the file.
- PPI (pixels per inch) is how many image pixels are laid across one inch of a screen or a printed page. It depends on the size at which the image is shown.
- DPI (dots per inch) is how many ink dots a printer places per inch. It describes a printer's output, not the image file.
Only pixel dimensions are fixed inside the image. PPI and DPI come from how you display or print it.
Pixel dimensions are the real amount of detail
An image with 3000 × 2000 pixels holds 6,000,000 pixels, or 6 megapixels. That count is all the detail the file has. Pixel dimensions also drive file size, as the earlier storage formula showed: width × height × bytes per pixel.
width, height = 3000, 2000
megapixels = width * height / 1_000_000
print(megapixels) # 6.0PPI links pixels to physical size
PPI is a ratio. Divide the pixel dimensions by the physical size to get the PPI.
def ppi(pixels, inches):
return pixels / inches
def print_size_inches(pixels, target_ppi):
return pixels / target_ppi
print(ppi(3000, 10)) # 300.0 (3000 px across 10 in)
print(print_size_inches(3000, 300)) # 10.0 in wide at 300 PPI
print(print_size_inches(3000, 150)) # 20.0 in wide at 150 PPIThe same 3000-pixel-wide image can be a sharp 10-inch print at 300 PPI or a softer 20-inch print at 150 PPI. The pixels did not change. Only the spacing did.
PPI versus DPI
The two terms are often swapped, but they mean different things.
| Term | Measures | Belongs to |
|---|---|---|
| Pixel dimensions | Width × height in pixels | The image file |
| PPI | Pixels per inch of display or print | The image at a chosen size, or a screen |
| DPI | Ink dots per inch | The printer |
A printer may use many tiny dots to make one pixel's color. A printer set to 1200 DPI does not need a 1200 PPI image. Photos usually look good at about 300 PPI for close viewing, and large items viewed from far away, such as posters, can use less.
The metadata trap
Image files can store a PPI value in their metadata, for example "72 PPI" or "300 PPI". This value is only a hint for software about the default print size. It does not change the pixels.
Changing a 1000 × 1000 image from "72 PPI" to "300 PPI" without resampling changes nothing in the image. It only changes the print size the software suggests, from about 13.9 inches to 3.3 inches. Web browsers ignore this value entirely and show one image pixel per CSS pixel, scaled by the screen's pixel density.
Resampling
Resampling changes the pixel dimensions. Downsampling removes pixels and usually looks fine. Upsampling adds pixels by interpolating between neighbors, so it cannot recover lost detail. A common rule is to start with enough pixels and reduce, not the other way around.
Quick checklist
- Find the pixel dimensions of your image.
- Decide the final physical size, or the screen size in CSS pixels.
- Divide pixels by inches to see the effective PPI.
- Compare it with the target: about 300 PPI for close print, and less for large distant prints.
Exercise
An image is 2400 × 1800 pixels. What is the largest width, in inches, it can print at 300 PPI, and what is the effective PPI if you print it 12 inches wide?
Show answer
At 300 PPI the width is 2400 / 300 = 8 inches. Printed 12 inches wide, the effective PPI is 2400 / 12 = 200 PPI.
Exercise
You change an image's metadata from 72 PPI to 300 PPI without resampling. Did the image gain detail? Explain.
Show answer
No. The pixel dimensions are unchanged, so the detail is the same. Only the suggested print size changed.