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
PNG Signature and IHDR
| Offset | Hex | ASCII | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0000 | 89504E470D0A1A0A0000000D49484452 | .PNG........IHDR | |||||||||||||||
| 0010 | 00000100000001000802000000000000 | ............. | |||||||||||||||
Chunk Structure
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.
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.
XML:com.adobe.xmp\0eXIf: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
Verify Signature
Check for PNG signature: 89 50 4E 47 0D 0A 1A 0A
Parse Chunks
Read each chunk's length, type, and validate CRC
Filter Metadata Chunks
Identify and skip tEXt, zTXt, iTXt, eXIf, tIME chunks
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)