Image Tools

How DPI Metadata Is Stored in Image Files

A Small Header Field, Separate From the Image Data

Image file formats separate two kinds of information: the actual pixel data (the bulk of the file), and header metadata describing properties of that data โ€” including, often, an intended density value. Editing DPI means locating and rewriting this specific header field, leaving the much larger block of pixel data completely untouched.

Where It Lives in JPEG Files

JPEG files store density information in a header segment (commonly the JFIF header), which includes fields for the horizontal and vertical density values along with a unit flag indicating whether those numbers mean pixels-per-inch or pixels-per-centimeter. A tool that changes DPI locates this specific segment and overwrites just those few bytes.

Where It Lives in PNG Files

PNG files store an equivalent value in a chunk called pHYs (physical pixel dimensions), which records pixel density along with a unit specifier. Like JPEG's density header, this is a small, isolated piece of metadata distinct from the actual compressed pixel data stored elsewhere in the file.

Why This Confirms the Metadata-Only Nature of the Change

Because the density value lives in a small, distinct header field rather than being calculated from or tied to the pixel data itself, changing it is a genuinely trivial edit โ€” locate a few bytes, overwrite them with a new number, leave everything else in the file exactly as it was. This is precisely why the operation can't add detail: it isn't touching the part of the file that contains any actual image detail to begin with.

A Basic Implementation Sketch

// Conceptual outline -- actual binary parsing
// depends on the specific image format's header layout
function setImageDPI(fileBytes, newDPI) {
  const densityFieldOffset = findDensityHeaderOffset(fileBytes);
  writeUInt16(fileBytes, densityFieldOffset, newDPI);     // horizontal
  writeUInt16(fileBytes, densityFieldOffset + 2, newDPI); // vertical
  return fileBytes; // pixel data untouched
}

Prefer not to handle the binary details yourself?

Open DPI Converter