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}
{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"
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: