.PNG
Portable Network Graphics
Introduction
PNG is a raster image format with lossless compression. It was designed in 1995 and 1996 as a free replacement for GIF, whose LZW compression was then covered by a patent. It became a W3C Recommendation in 1996 and an international standard, ISO/IEC 15948, in 2004.
A PNG can hold greyscale, truecolour or palette images at up to 16 bits per channel,
with full alpha transparency. It is the usual format for screenshots, diagrams and web
graphics with sharp edges. Animated PNG (APNG, sometimes saved as .apng)
adds frames through extra chunks that older readers skip.
Software
- GIMP (Windows, macOS, Linux)
- Adobe Photoshop (Windows, macOS)
- Krita (Windows, macOS, Linux)
- Paint.NET (Windows)
- IrfanView (Windows)
- XnView MP (Windows, macOS, Linux)
- ImageMagick (Windows, macOS, Linux)
- Squoosh (web browser)
- OptiPNG (Windows, macOS, Linux)
- libpng (the reference library)
Structure
A PNG file is an 8-byte signature followed by a series of chunks. Each chunk is a
4-byte big-endian length, a 4-byte type such as IHDR, the data, and a CRC-32
of the type and data. The case of each letter in the type carries a flag: an upper case
first letter marks a chunk that a reader must understand.
The IHDR chunk comes first and gives the width, height, bit depth, colour
type and interlace method. A palette image has a PLTE chunk. The pixels are
filtered row by row, compressed as one zlib stream and split across one or more
IDAT chunks. IEND closes the file. Optional chunks carry
transparency, gamma, colour profiles, text and timestamps.
0Signature89 50 4E 47 0D 0A 1A 0A8 bytes8IHDR width, height, bit depth, colour type, interlace25 bytes33PLTE, tRNS, gAMA, tEXt … optional chunksvaries…IDAT the compressed pixels, in one or more chunksvaries…IEND the end of the image12 bytes