wire / wire-format / png-structure

PNG file structure

A PNG file starts with an 8-byte signature, then a sequence of chunks. Each chunk: 4-byte length (big-endian), 4-byte type (ASCII), length bytes of data, 4-byte CRC-32 (over type+data). Critical chunks: IHDR (image header), PLTE (palette), IDAT (image data), IEND (end). Ancillary chunks: tEXt/zTXt/iTXt (metadata), gAMA, cHRM, sRGB, pHYs, tIME, bKGD, etc.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: PNG file structure

wire format

spec: W3C PNG specification (ISO/IEC 15948)

A PNG file starts with an 8-byte signature, then a sequence of chunks. Each chunk: 4-byte length (big-endian), 4-byte type (ASCII), length bytes of data, 4-byte CRC-32 (over type+data). Critical chunks: IHDR (image header), PLTE (palette), IDAT (image data), IEND (end). Ancillary chunks: tEXt/zTXt/iTXt (metadata), gAMA, cHRM, sRGB, pHYs, tIME, bKGD, etc.

fieldsizemeaning
PNG signature8 bytes0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A.
Chunk length4 bytesLength of the chunk data field (big-endian). Max 2^31-1.
Chunk type4 bytesASCII type code (e.g. 'IHDR', 'IDAT', 'IEND', 'PLTE', 'tEXt').
Chunk data= lengthThe chunk's payload (structure depends on type).
Chunk CRC4 bytesCRC-32 (IEEE) over chunk type + chunk data.
IHDR data13 bytesWidth (4), Height (4), Bit depth (1), Color type (1), Compression (1, always 0), Filter (1, always 0), Interlace (1, 0/1).

example:

89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 01 00 00 00 01 08 02 00 00 00 90 77 53 de

PNG signature + IHDR for a 1x1 8-bit RGB image


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/png-structure or /wire-format/png-structure.json