8000 GitHub - andrewschaaf/node-png-guts: Helpers for working for working with PNG internals
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

andrewschaaf/node-png-guts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

Helpers for working for working with PNG internals

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0