PicScrub logoPicScrub
Back to Formats

PNG Format

Portable Network Graphics

Chunk-Based Structure

PNG has one of the cleanest file formats around. Everything is organized into "chunks", which are self-contained blocks with a type, data, and checksum. The elegant part is that decoders can skip chunks they don't understand, which is how PNG supports metadata without breaking older software.

The clever bit is in the chunk naming: if the first letter is uppercase, it's "critical" (the image won't display without it). Lowercase means "ancillary", meaning nice to have but not essential. All the metadata chunks we care about are ancillary, which is why we can safely remove them.

PNG File Structure

Signature
IHDR
Metadata
IDAT
IEND
Signature
8 bytes
89 50 4E 47 0D 0A 1A 0A
IHDR
25 bytes
Image header (required)
Metadata
100 bytes
tEXt, iTXt, eXIf chunks
IDAT
Variable length
Compressed image data
IEND
12 bytes
Image end marker

PNG Signature and IHDR

PNG Signature
IHDR Length (13)
IHDR Type
Width (256)
Height (256)
Bit depth, color type, etc.
OffsetHexASCII
0000
89504E470D0A1A0A0000000D49484452
.PNG........IHDR
0010
00000100000001000802000000000000
.............

Chunk Structure

LengthTypeDataCRC32
4 bytes4 bytesVariable4 bytes

Chunk Type Naming Convention

  • First letter uppercase = Critical chunk (must be understood)
  • First letter lowercase = Ancillary chunk (optional, can be ignored)
  • Second letter = Public (uppercase) or Private (lowercase)

Critical Chunks

These chunks must be present and understood for the image to be valid. PicScrub always preserves critical chunks.

IHDR:Image Header

First chunk after signature. Contains width, height, bit depth, color type, compression method, filter method, and interlace method. Exactly 13 bytes of data.

IDAT:Image Data

Contains the compressed (zlib/deflate) image data. May be split across multiple IDAT chunks. All IDAT chunks must be consecutive.

IEND:Image End

Marks the end of the PNG datastream. Must be the last chunk. Has zero data bytes.

PLTE:Palette

Required for indexed color images (color type 3). Contains 1–256 RGB palette entries.

Metadata Chunks

Ancillary chunks that can contain privacy-sensitive metadata. These are the chunks PicScrub removes.

tEXt:Uncompressed Text

Key-value pairs in Latin-1 encoding. Common keys: Author, Description, Copyright, Creation Time, Software.

Format: keyword + null + text

zTXt:Compressed Text

Same as tEXt but with zlib compression. Used for longer text content.

iTXt:International Text

UTF-8 text with optional compression. Supports language tags and translated keywords. Used for XMP metadata.

XMP keyword: XML:com.adobe.xmp\0

eXIf:EXIF Data

Registered as a PNG extension in 2017. Contains raw EXIF data in TIFF format, same structure as JPEG EXIF. Can contain GPS, timestamps, device info.

iCCP:ICC Color Profile

Embedded ICC color profile. Compressed with zlib. PicScrub preserves by default for color accuracy.

tIME:Last Modification Time

Seven bytes: year (2), month, day, hour, minute, second. Reveals when the image was last modified.

Color-Related Chunks

These chunks affect color rendering but typically don't contain personal information. PicScrub preserves them by default.

sRGB

Indicates sRGB color space. Single byte for rendering intent.

gAMA

Gamma value as 4-byte unsigned integer (scaled by 100,000).

cHRM

Primary chromaticities and white point coordinates.

sBIT

Original sample bit depths for each channel.

CRC32 Verification

Every PNG chunk includes a CRC32 checksum calculated over the chunk type and data. This ensures data integrity.

CRC Calculation

CRC32 input = chunk_type (4 bytes) + chunk_data (N bytes)
CRC32 output = 4 bytes appended after chunk data

// PNG uses CRC-32 polynomial: 0xEDB88320

Why PicScrub Validates CRC

When reading PNG files, PicScrub validates each chunk's CRC to ensure data integrity. Corrupted chunks are handled gracefully.

How PicScrub Processes PNG

1

Verify Signature

Check for PNG signature: 89 50 4E 47 0D 0A 1A 0A

2

Parse Chunks

Read each chunk's length, type, and validate CRC

3

Filter Metadata Chunks

Identify and skip tEXt, zTXt, iTXt, eXIf, tIME chunks

4

Reconstruct File

Write signature + filtered chunks + IEND

Preserved Chunks

  • • IHDR, PLTE, IDAT, IEND (critical)
  • • sRGB, gAMA, cHRM (color)
  • • iCCP (color profile, optional)
  • • pHYs (pixel dimensions)
  • • tRNS (transparency)

Removed Chunks

  • • tEXt (text metadata)
  • • zTXt (compressed text)
  • • iTXt (international text, XMP)
  • • eXIf (EXIF data)
  • • tIME (modification time)