Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Helpers for working for working with PNG internals

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Command-line tool

cat foo.png | png-guts --strip-ancillary > foo-normalized.png

Options:

--strip-text            strip {iTXt,tEXt,zTXt} chunks
--strip-ancillary       strip all chunks other than {IHDR,PLTE,IDAT,IEND}

NodeJS library example

{PNG_FILE_HEADER, PNGChunkReader} = require 'png-guts'

inspect_png = (readable_stream) ->
  size = PNG_FILE_HEADER.length
  reader = new PNGChunkReader readable_stream
  reader.on 'chunk', (type, data) ->
    console.log "#{type} chunk: #{data.length} bytes"
    size += data.length
  reader.on 'end', () ->
    console.log "file size: #{size.length} bytes"

What is a PNG?

Every PNG file consists of 89 50 4E 47 0D 0A 1A 0A followed by chunks.

Every chunk is encoded thusly:

4 bytes     data length: N as a big-endian unsigned 32-bit integer
4 bytes     chunk type: usually ASCII
N bytes     ...data...
4 bytes     CRC

These are four critical chunk types:

IHDR: the first chunk, with metadata

PLTE: a color palette

IDAT: image data

IEND: the last chunk

Further reading:

Something went wrong with that request. Please try again.