How to Check Image DPI and Print Size With Python
Why pixel dimensions and print size get confused
An image that looks sharp on a monitor may become noticeably soft when printed as a brochure, catalog page, product label, or large display. The common mistake is treating a file’s DPI field as proof of image quality. A JPEG marked 300 DPI is not automatically suitable for a large poster, and a file marked 72 DPI is not necessarily low resolution. The decisive information is how many actual pixels are available and how large those pixels must be printed.
Image production teams often receive hundreds of files from cameras, marketplaces, designers, and scanning systems. Some contain reliable resolution metadata; others have missing or misleading values. A small automated inspection can identify files that need resizing, replacement, or manual review before they reach a print layout.
Understand pixels, PPI, and DPI
Pixel dimensions describe the raster image itself. A photograph measuring 2400 by 1600 pixels contains the same number of samples whether its metadata says 72, 96, or 300 pixels per inch. PPI, or pixels per inch, describes the density at which those samples are placed on the printed page. DPI technically describes printer dot placement, which is not identical to source-image PPI, although software interfaces often use the terms interchangeably.
To estimate print width, divide pixel width by the intended PPI. A 2400-pixel-wide image at 300 PPI spans eight inches. At 150 PPI it spans sixteen inches. Neither calculation creates or destroys pixels. It only changes the physical dimensions associated with them. This distinction is essential when evaluating product image editing workflows for printed catalogs.
Decide the effective resolution before auditing
Effective PPI is determined by the final placed size, not merely by the resolution tag stored in the file. A 3000-pixel image placed ten inches wide has 300 effective PPI; place the same image twenty inches wide and it falls to 150. If a designer crops the image, the usable pixel count becomes smaller still. A preflight report should therefore ask for target width and height rather than assuming that embedded metadata reflects the final layout.
Three hundred PPI is a common starting point for detailed print work viewed closely, but it is not a universal requirement. Large signs viewed from several meters away can work at much lower effective resolution. Fine typography and line art often need different handling from continuous-tone photographs. Confirm the print provider’s specifications and viewing distance before labeling an image as unsuitable.
Inspect images with Pillow
Python’s Pillow library can read pixel dimensions, format, color mode, and resolution metadata for many common raster formats. Install it in a virtual environment with python -m pip install Pillow. Use Image.open() inside a context manager so file handles are closed. The size property returns pixel width and height, while info.get('dpi') may return a tuple when the format stores resolution information.
Resolution metadata should be treated as optional. Some PNG files store pixels per meter, which Pillow may convert to approximate DPI values. JPEG density fields can also be absent or rounded. Avoid rejecting files simply because the metadata field is missing. A 4000-pixel photograph can still be excellent source material when its resolution tag is empty.
Calculate usable print dimensions
Suppose a file is 3600 by 2400 pixels and the desired print density is 300 PPI. Its maximum dimensions at that density are twelve by eight inches. If the design needs a fifteen-inch width, the effective density becomes 240 PPI. Whether that is acceptable depends on the job, the image’s actual detail, and the printer’s expectations.
An automated checker can calculate both maximum print size at a chosen density and effective PPI at a specified placement size. The first answers how large the image can be printed under a target rule. The second answers whether it meets the requirements of an existing layout. For mixed portrait and landscape assets, evaluate width and height independently rather than comparing only total megapixels.
Build a simple batch image audit
Create an input folder containing copies of the images you want to inspect. The following Python example reads common raster formats, records source dimensions and embedded DPI when available, and calculates effective PPI for a target placement of eight by six inches. It writes a CSV report rather than modifying the source files. Change the placement dimensions to match your own layout.
from pathlib import Path
import csv
from PIL import Image, UnidentifiedImageError
folder = Path('input_images')
report = Path('image_print_audit.csv')
width_in, height_in = 8.0, 6.0
extensions = {'.jpg', '.jpeg', '.png', '.tif', '.tiff', '.webp'}
with report.open('w', newline='', encoding='utf-8') as output:
writer = csv.writer(output)
writer.writerow(['file', 'width_px', 'height_px', 'dpi_tag',
'effective_ppi_x', 'effective_ppi_y', 'status'])
for path in sorted(folder.iterdir()):
if not path.is_file() or path.suffix.lower() not in extensions:
continue
try:
with Image.open(path) as im:
w, h = im.size
dpi = im.info.get('dpi', '')
ppi_x = round(w / width_in, 1)
ppi_y = round(h / height_in, 1)
status = 'review' if min(ppi_x, ppi_y) < 300 else 'meets target'
writer.writerow([path.name, w, h, str(dpi),
ppi_x, ppi_y, status])
except (OSError, UnidentifiedImageError) as exc:
writer.writerow([path.name, '', '', '', '', '', f'error: {exc}'])
The code uses the smaller of the horizontal and vertical effective PPI values as a conservative signal. It does not account for crop, rotation, or image quality, so the result is a screening tool rather than a final approval. A square photo forced into an eight-by-six layout might be cropped or distorted; determine its real placement before making production decisions.
Handle aspect ratios and cropping correctly
Print dimensions cannot be evaluated independently of composition. A 4:3 image placed in a 16:9 frame must either leave empty space, be stretched, or be cropped. Stretching changes proportions and is usually undesirable. Cropping removes pixels along one axis, so the final effective PPI must be recalculated using the surviving region.
For a center crop, first determine the crop rectangle in pixel coordinates that matches the frame’s aspect ratio. Then divide that rectangle’s width and height by the physical placement dimensions. For example, cropping a 4000-by-3000 image to 16:9 leaves roughly 4000 by 2250 pixels. The original height of 3000 is no longer available for the placed image. Keep the unedited master so a designer can reposition the crop if important content is cut off.
Distinguish resolution problems from poor sharpness
A file can pass a pixel-count threshold while still looking poor in print. Motion blur, missed focus, heavy noise reduction, excessive JPEG compression, and artificial sharpening all reduce useful detail. Upscaled files can report impressive dimensions without containing the fine texture expected from a genuine high-resolution capture.
Review representative images at an appropriate magnification and inspect edges, product labels, fabric patterns, and small text. A sharpness metric based on image gradients can help prioritize review, but it should not be treated as a universal pass/fail score. Smooth studio backgrounds naturally have fewer edges than detailed architecture. For ecommerce imagery, consider the distinction between pixel adequacy and the focus-stacking techniques used to capture real detail.
Check color mode and transparency
Print readiness also involves color handling. Pillow may report RGB, RGBA, CMYK, grayscale, or palette modes. Those labels are useful, but they do not fully describe color appearance. Embedded ICC profiles and the print shop’s conversion requirements matter. Do not blindly convert every RGB image to CMYK with a generic script, because an unmanaged conversion can alter colors unexpectedly.
Transparent product cutouts require special attention. A file with an alpha channel can appear correct against a checkerboard yet develop halos when composited onto a white or colored page. Inspect transparency at the actual background color and preserve the original alpha when possible. The process connects naturally to image masking and edge preparation, which are separate from resolution checks.
Recognize metadata that cannot be trusted
Files are frequently resaved by chat applications, content management systems, image editors, and export tools. Those operations may strip ICC profiles or resolution tags, recompress images, or change dimensions. A source file labeled 300 DPI might have been enlarged from a small thumbnail. Conversely, a camera image marked 72 DPI may have enough pixels for an excellent print.
Record the original filename, pixel dimensions, file format, and embedded metadata in the audit. When practical, also capture the source or export history. This gives the production team a traceable reason for accepting or rejecting an asset rather than relying on a single metadata field.
Create a practical quality-control workflow
Start by collecting the intended physical placement dimensions from the designer or print specification. Inspect every file for readability, format, pixel dimensions, and color mode. Calculate effective PPI, then separate clear passes from borderline cases and obvious failures. Manually review a representative sample of each group, especially images with fine text, product packaging, or aggressive cropping.
Keep a consistent report with fields for image identifier, source dimensions, target placement, effective PPI, crop notes, profile status, and review decision. When an image fails, request a better original before applying enlargement. If enlargement is unavoidable, document it and inspect a physical proof. This approach complements broader catalog data quality checks because image defects can be linked back to the correct SKU or asset record.
Common mistakes to avoid
Changing a DPI tag from 72 to 300 without adding pixels does not improve print detail. Resampling an image upward may change its pixel dimensions, but it cannot reliably reconstruct information that was never captured. Likewise, a high-megapixel file does not guarantee quality if it has blur, compression damage, or incorrect focus.
Another mistake is approving images at a generic size rather than their actual placement. A photo that works as a two-inch catalog thumbnail may fail as a full-page hero image. Avoid automatic rejection based on one threshold, and never let a spreadsheet status replace a visual inspection of important print assets.
Conclusion
Reliable print-image preflight begins with actual pixel dimensions and the size at which the image will appear. Python can automate the repetitive measurements, identify missing metadata, and produce a useful review queue without changing original files. The final decision still depends on crop, detail, color handling, and the requirements of the print process.
By separating embedded DPI from effective PPI and combining automated checks with selective visual review, teams can reduce avoidable rework and make more defensible decisions about which images are ready for production.
