PerfectVector
Studio
By Irene Kim

Read PNG pHYs to Check Print Size and Resolution

Read PNG pHYs metadata, convert pixels per meter to pixels per inch, and calculate the suggested print size. Check what to do when the density is missing.

6 min read
On this page

If a PNG's pHYs chunk uses meters, multiply each pixels-per-meter value by 0.0254 to get pixels per inch (PPI). Divide the width and height in pixels by their respective PPI values to get the size in inches implied by the tag. If the chunk is missing or has an unknown unit, use the size at which you plan to place the image.

Check whether the PNG stores a physical density

The optional pHYs chunk stores horizontal and vertical pixels-per-unit values and a unit flag. The W3C PNG specification assigns these meanings to the flag.

What you findWhat you can calculate
Unit 1, positive X and Y valuesPixels per meter on each axis, and a physical size from the image's pixel dimensions
Unit 0, positive X and Y valuesPixel aspect ratio only. Equal values describe square pixels.
No pHYs chunkThe specification assumes square pixels and leaves their physical size unspecified.

PPI counts image pixels per inch at a physical size. DPI counts device dots per inch in print terminology. If a metadata viewer labels its image density field “DPI,” check what the value represents before using it. For device dots and screen frequency, see how PPI, DPI and LPI differ in halftone printing.

Read the chunk and calculate both dimensions

Use Python 3.8 or newer and a copy of your PNG. The script reads the header and searches for pHYs before the first image-data chunk. It leaves the file untouched.

  1. Replace artwork.png with your file name and run the command.
  2. Check the unit flag and read the PPI and size if the flag is 1 and both values are positive.
  3. If the script reports that physical size is unavailable, use the placed-size calculation below.
python3 - artwork.png <<'PY'
import sys
from struct import unpack
 
with open(sys.argv[1], "rb") as png:
    if png.read(8) != b"\x89PNG\r\n\x1a\n":
        raise SystemExit("Expected a PNG file.")
 
    width = height = 0
    while len(header := png.read(8)) == 8:
        size, kind = unpack(">I4s", header)
        if kind == b"IHDR" and size == 13:
            width, height = unpack(">II", png.read(8))
            png.seek(9, 1)  # Remaining IHDR bytes and CRC
            print(f"{width} x {height} px")
        elif kind == b"pHYs" and size == 9:
            x, y, unit = unpack(">IIB", png.read(9))
            print(f"pHYs: {x} x {y} pixels per unit, unit {unit}")
            if unit == 1 and min(x, y, width, height) > 0:
                x_ppi, y_ppi = x * 0.0254, y * 0.0254
                print(f"{x_ppi:.4f} x {y_ppi:.4f} PPI")
                print(f"{width / x_ppi:.2f} x {height / y_ppi:.2f} in")
            else:
                print("physical size unavailable")
            break
        elif kind in (b"IDAT", b"IEND"):
            print("no pHYs; physical size unavailable")
            break
        else:
            png.seek(size + 4, 1)  # Chunk data and CRC
PY

The conversion uses NIST's exact inch definition. One inch is 2.54 centimeters, or 0.0254 meters. Keep the full converted PPI for the size calculation and round the displayed result afterward. If the two density values differ, use the horizontal value for width and the vertical value for height.

Compare the same pixels at two tagged print sizes

We generated a 1,200 × 750 px label and wrote separate pHYs values into copies of its PNG. The compressed image data (IDAT) and the decoded RGB pixels matched byte for byte across the copies.

Identical label artwork in three PNGs, tagged at about 300 PPI, about 150 PPI, and an unspecified physical density
The two meter-based tags imply different print sizes for the same 1,200 × 750 pixels. The unit-0 file specifies a 1:1 pixel aspect ratio.
pHYs X × YUnitPPI on each axisSize implied by the tag
11,811 × 11,8111299.99944.00 × 2.50 in
5,906 × 5,9061150.01248.00 × 5.00 in
11,811 × 11,8110UnspecifiedUnspecified

The file with the 150 PPI tag implies a label roughly twice as wide as the one tagged at 300 PPI. Both contain the same 1,200 horizontal pixels. You can give either file an explicit 6-inch width in a layout. At that width its effective horizontal density is 1,200 ÷ 6, or 200 PPI.

Confirm the placed size before printing

In a page layout, read the width and height of the placed image and calculate effective PPI from those dimensions. If the file supplies no usable density, set the intended physical dimensions yourself and run the same calculation. Check the print preview for scaling such as “Fit to page,” which can change the output size.

If you need to change the suggested print size while keeping the pixel grid, use an image editor's size controls with resampling disabled. Adobe's Photoshop Image Size documentation distinguishes the pixel dimensions, physical dimensions, and resolution fields. After exporting the PNG, check both its pixel dimensions and its pHYs values again. If the exported file has no usable tag, set its size explicitly when placing it.

FAQ

Does changing PNG pHYs add pixels?

Changing the pHYs chunk alone changes the density or aspect-ratio metadata. The pixel dimensions and image data stay the same. Resampling is a separate operation that changes the pixel grid.

What print size does a PNG with no pHYs have?

The file supplies no physical pixel size. Use the size specified in your layout or print job. Divide the image's pixel width and height by the corresponding dimensions in inches to find the effective PPI.

What does 11,811 pixels per meter mean in a PNG?

With unit 1, 11,811 pixels per meter is about 300 PPI on the axis that stores that value. With unit 0, only the ratio between the horizontal and vertical values carries meaning.

Start with the artwork you need

PerfectVector can recover editable SVG paths if a logo or other flat artwork exists only as a PNG and the print workflow calls for vector geometry. Use the image-to-vector tool on that artwork, compare the resulting outlines and small gaps with the source, then set the SVG's physical size in your layout. The PNG-to-SVG fidelity guide shows what to inspect in a trace.

Sources

  1. W3C PNG Specification, Third Edition — Physical pixel dimensions — Defines the pHYs fields, unit flag, and behavior when the chunk is absent.
  2. NIST SI Units — Length — Gives the exact inch-to-centimeter conversion used in the PPI calculation.
  3. Adobe Photoshop Help — Set image size and resolution — Explains the Image Size fields and the role of resampling.

More from the blog

PerfectVector

Turn your image file into an
editable SVG

Vectorize and inspect previews for free, with no daily limit.