Sub topic 4
Resolution, Pixel Dimensions and PPI/DPI
Prerequisites
This chapter assumes you know that a raster image is a grid of pixels, that a pixel is one colored square (or dot) in that grid, and that files such as .jpg and .png hold raster data. You do not need to know anything about print production. The chapter builds that from scratch.
Why "resolution" is a confusing word
People use "resolution" for at least three different things:
- The pixel dimensions of an image, such as 1920 × 1080.
- The pixel density of an image or device, such as 300 pixels per inch.
- The sharpness you actually perceive, which depends on both of the above and on viewing distance.
Most mistakes in this area come from mixing these up. The rest of the chapter keeps them apart.
Pixel dimensions: the only number the file really stores
The pixel dimensions of a raster image are its width and height counted in pixels. A photo that is 4000 × 3000 pixels contains 12,000,000 pixels, or 12 megapixels. This is a fact about the file's data. It does not change when you print the image, display it on a bigger screen, or change a setting called "resolution" in an editor.
Pixel dimensions set the ceiling on detail. An image can never contain more real detail than its pixels hold. You can make the grid larger by resampling, but the new pixels are guessed from their neighbors and add no new information.
Pixel dimensions also drive file size before compression. The calculation is width × height × bytes per pixel:
width, height = 4000, 3000
bytes_per_pixel = 3 # 8 bits each for red, green and blue
size_bytes = width * height * bytes_per_pixel
print(size_bytes) # 36000000
print(round(size_bytes / 2**20, 1)) # 34.3 (MiB, uncompressed)Doubling both width and height quadruples the pixel count and therefore the uncompressed size. That is why a modest increase in dimensions can make a page noticeably slower to load.
PPI: pixels per inch
PPI (pixels per inch) describes how many pixels are placed along one inch of a physical surface. It connects the abstract grid to a real size. The relationship is:
- physical size = pixel dimensions ÷ PPI
- PPI = pixel dimensions ÷ physical size
For example, a 3000 × 2000 pixel image at 300 PPI covers 10 × 6.67 inches. The same file at 100 PPI covers 30 × 20 inches. The pixels have not changed. Only the size each pixel is given has changed.
def print_size_inches(width_px, height_px, ppi):
return width_px / ppi, height_px / ppi
for ppi in (72, 150, 300):
w, h = print_size_inches(3000, 2000, ppi)
print(f"{ppi:>3} PPI -> {w:.1f} x {h:.1f} inches")Running this prints:
72 PPI -> 41.7 x 27.8 inches
150 PPI -> 20.0 x 13.3 inches
300 PPI -> 10.0 x 6.7 inchesThe PPI value stored in a file is only a hint
Many image files carry a PPI number in their metadata, often 72 or 96 by default. It is a suggestion about intended print size. It does not change any pixel. Two files with identical pixels and different metadata PPI are the same picture. Editors usually offer a "resample" checkbox for this reason:
- With resampling off, changing PPI only changes the stated physical size. Pixels are untouched.
- With resampling on, changing PPI or physical size makes the editor add or remove pixels.
Confusing these two modes is a very common error. Someone sets "300 PPI" on a 600 × 400 web image, expecting a print-quality result, and gets a 2 × 1.33 inch picture, not a better one.
DPI: dots per inch
DPI (dots per inch) describes how many ink or toner dots a printer lays down per inch. It is a property of the output device, not of the image file. A printer rated at 1200 DPI can place up to 1200 dots along an inch, but a printer builds one image pixel from many dots, using patterns of a few ink colors to imitate many shades.
In everyday speech, "DPI" is often used where "PPI" is correct, including in software dialogs and on spec sheets. A practical rule: if the number describes an image file or a screen, read it as PPI. If it describes a printer or a scanner's sampling, it is genuinely DPI (scanners often use "SPI", samples per inch, as well).
| Term | Measures | Belongs to | Typical example |
|---|---|---|---|
| Pixel dimensions | Pixels across and down | The image file | 1920 × 1080 |
| PPI | Pixels per inch | An image at a chosen size, or a screen | 300 PPI for print, about 110 to 460 PPI for screens |
| DPI | Ink dots per inch | A printer or scanner | 600 or 1200 DPI |
How much PPI do you need?
The answer depends on how closely the image is viewed, because the eye can only separate details above a certain angular size. Closer viewing needs more pixels per inch.
| Use | Common target | Reason |
|---|---|---|
| Magazine, book, brochure | 300 PPI | Held close, readers see fine detail |
| Poster on a wall | 150 PPI | Viewed from an arm's length or more |
| Large banner or billboard | 20 to 75 PPI | Viewed from many meters away |
| Web or app on a typical screen | Defined in pixels, not inches | Browser scales to the device |
These are guidelines, not laws. Photos with soft detail tolerate lower PPI than text or line art. A 200 PPI print of a landscape often looks fine, while 200 PPI text in a raster image can look rough.
Working out the pixels you need
Start from the physical size and target PPI, then multiply:
def pixels_needed(width_in, height_in, ppi):
return round(width_in * ppi), round(height_in * ppi)
print(pixels_needed(8, 10, 300)) # (2400, 3000)
print(pixels_needed(24, 36, 150)) # (3600, 5400)An 8 × 10 inch print at 300 PPI needs 2400 × 3000 pixels, which is 7.2 megapixels. Almost any modern camera exceeds that, so ordinary prints are rarely limited by the camera. Large prints are where limits appear.
Resolution on screens
Screens complicate the picture because the operating system and browser decouple image pixels from physical screen pixels.
Device pixels and CSS pixels
On the web, sizes written in CSS use CSS pixels, a unit that is roughly the same apparent size across devices. A high-density display may use 2 or 3 physical device pixels for each CSS pixel. The ratio is the device pixel ratio (DPR). A phone with a DPR of 3 packs nine physical pixels into the area of one CSS pixel.
For a raster image to look sharp, it needs about as many image pixels as the device pixels it will cover. An image displayed at 300 CSS pixels wide needs:
- 300 pixels wide on a DPR 1 screen,
- 600 pixels wide on a DPR 2 screen,
- 900 pixels wide on a DPR 3 screen.
If the file has fewer pixels, the browser stretches it and it looks soft.
Serving more than one size
HTML lets you offer several widths and let the browser pick the best one:
<img
src="photo-600.jpg"
srcset="photo-600.jpg 600w, photo-1200.jpg 1200w, photo-1800.jpg 1800w"
sizes="(max-width: 600px) 100vw, 600px"
alt="Mountain lake at sunrise"
width="600" height="400">Here srcset lists the available files with their pixel widths, and sizes tells the browser how wide the image will be on the page. The browser multiplies by its DPR and picks a suitable file. The width and height attributes reserve space so the page does not jump while the image loads.
Common errors
- Setting PPI to 300 and expecting sharper output. Without resampling, only the metadata changes. The detail is whatever the pixels already held.
- Upscaling a small image to reach a target size. Interpolation (guessing new pixels from nearby ones) smooths the result but cannot recover lost detail. Upscaled photos look soft, and upscaled graphics look blurry at edges.
- Saving a web graphic "at 72 DPI" and calling it web-ready. Browsers ignore the stored PPI. Only the pixel dimensions matter on screen.
- Judging print quality on screen at 100% zoom. At 100% zoom, one image pixel maps to one screen pixel, which shows far more magnification than a print viewed at a normal distance.
- Quoting printer DPI as image resolution. A 1200 DPI printer does not need a 1200 PPI image. Roughly 300 PPI is enough for most print jobs.
- Downscaling and then upscaling again. Reducing pixels discards data permanently. Keep the original and export copies from it.
Vector images and resolution
A vector image stores shapes, not a pixel grid, so it has no pixel dimensions or intrinsic PPI. It gains pixels only when it is rasterized for a screen or printer, and it can be rasterized at any size. This is why a logo drawn as vector can be printed on a business card or a building without a resolution question. The next chapters on scaling and conversion build on this point.
Quick reference
- Pixel dimensions are what the file contains. They fix the maximum detail.
- PPI links pixel dimensions to a physical size: size = pixels ÷ PPI.
- DPI belongs to printers and scanners and counts ink dots, not image pixels.
- Metadata PPI is a hint. Resampling is the only operation that changes pixels.
- Use about 300 PPI for close-held print, less for large or distant output.
- On screens, think in device pixels: multiply layout width by DPR.
Exercise
You need a 12 × 18 inch poster to be printed at 150 PPI. Your photo is 1800 × 2400 pixels. (a) How many pixels does the print need? (b) Is the photo big enough? (c) What PPI would the photo give at 12 × 18 inches, and what would a client see if you only changed the metadata to 300 PPI?
Show answer
(a) 12 × 150 = 1800 and 18 × 150 = 2700, so the print needs 1800 × 2700 pixels. (b) The photo is 1800 × 2400, so the width is right but the height is short. Matching the 2:3 poster shape also means the photo's 3:4 ratio would have to be cropped or the missing 300 pixels filled in by upscaling. A crop to 1800 × 2700 is impossible without new pixels, so a small upscale or a slightly smaller print is needed. (c) Across the 12 inch width the photo gives 1800 ÷ 12 = 150 PPI. Changing only the metadata to 300 PPI would label it as a 6 × 8 inch image and change no pixels, so the real detail stays the same.
Exercise
A banner image is shown at 400 CSS pixels wide on a phone with a device pixel ratio of 3. What is the smallest image width that stays sharp, and which of these files would you choose from a srcset: 400w, 800w, 1200w, 1600w?
Show answer
The phone needs 400 × 3 = 1200 device pixels across, so the smallest sharp image is 1200 pixels wide. Choose the 1200w file. The 1600w file would also look sharp but wastes bandwidth, and the 800w file would look soft.