zpng [![Build Status](https://secure.travis-ci.org/zed-0xff/zpng.png)](http://secure.travis-ci.org/zed-0xff/zpng) [![Dependency Status](https://gemnasium.com/zed-0xff/zpng.png)](https://gemnasium.com/zed-0xff/zpng) ====== Description ----------- A pure ruby PNG file manipulation & validation (If you need a high-level PNG creation toolkit - take a look at [SugarPNG](https://github.com/zed-0xff/sugar_png)) Installation ------------ gem install zpng Comparison ---------- * supports `iTXt` (international text) chunks * full support of 16-bit color & alpha depth Usage ----- # zpng -h Usage: zpng [options] filename.png -i, --info General image info (default) -c, --chunk(s) [ID] Show chunks (default) or single chunk by its # -m, --metadata Show image metadata, if any (default) -S, --scanlines Show scanlines info -P, --palette Show palette --colors Show colors used -E, --extract-chunk ID extract a single chunk -D, --imagedata dump unpacked Image Data (IDAT) chunk(s) to stdout -C, --crop GEOMETRY crop image, {WIDTH}x{HEIGHT}+{X}+{Y}, puts results on stdout unless --ascii given -A, --ascii Try to convert image to ASCII (works best with monochrome images) -N, --ansi Try to display image as ANSI colored text -2, --256 Try to display image as 256-colored text -W, --wide Use 2 horizontal characters per one pixel -v, --verbose Run verbosely (can be used multiple times) -q, --quiet Silent any warnings (can be used multiple times) -I, --console opens IRB console with specified image loaded ### Info # zpng qr_rgb.png [.] image size 35x35, 24bpp, COLOR_RGB [.] uncompressed imagedata size = 3710 bytes [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK ### Info (verbose) # zpng -v qr_rgb.png [.] image size 35x35, 24bpp, COLOR_RGB [.] uncompressed imagedata size = 3710 bytes 01 ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 |................| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 3678 bytes [.] CRC OK 00 00 00 23 00 00 00 23 08 02 00 00 00 |...#...#..... | [.] CRC OK 00 |. | [.] CRC OK 48 c7 bd 56 41 12 c4 20 08 d3 8e ff ff b2 7b 70 |H..VA.. ......{p| 86 d2 24 44 db c3 7a d8 d9 b6 08 18 03 a1 cf 39 |..$D..z........9| + 367 bytes [.] CRC OK ( add more `-v`'s for even more verbose output) ### Chunks # zpng --chunks qr_aux_chunks.png [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK [.] CRC OK ### ASCII source image: ![qr_rgb.png](https://github.com/zed-0xff/zpng/raw/master/samples/qr_rgb.png) # zpng --ascii --wide qr_rgb.png @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ @@ @@@@@@@@@@ @@ @@ @@@@@@@@ @@ @@ @@@@@@@@@@ @@@@@@@@@@@@@@ @@ @@ @@@@@@@@@@ @@@@@@@@@@ @@ @@ @@ @@ @@ @@@@ @@@@ @@ @@@@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@@@@@@@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@@@@@@@ @@ @@@@ @@ @@ @@ @@ @@@@@@@@@@ @@@@ @@@@ @@ @@@@ @@@@@@@@ @@@@@@@@@@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@@@@@@@@@@@@@@@@@@@ @@ @@ @@@@@@@@@@ @@ @@@@@@@@@@@@@@@@@@ @@ @@@@ @@ @@@@@@@@ @@ @@ @@@@@@@@ @@@@ @@ @@ @@@@ @@ @@@@@@ @@@@@@@@@@ @@ @@ @@ @@ @@@@@@ @@ @@ @@ @@ @@@@@@@@@@@@ @@ @@ @@@@ @@ @@ @@ @@ @@@@@@@@ @@ @@@@@@ @@@@ @@ @@@@@@ @@ @@@@@@ @@@@ @@ @@ @@ @@@@ @@ @@@@@@@@ @@ @@@@ @@ @@@@@@@@@@ @@@@@@ @@@@ @@ @@ @@ @@@@@@@@ @@ @@ @@@@@@@@ @@@@ @@ @@ @@ @@ @@ @@@@ @@@@ @@@@@@ @@ @@ @@@@ @@ @@ @@ @@@@@@@@ @@@@@@ @@ @@@@@@ @@@@@@ @@ @@@@ @@@@@@@@@@ @@ @@ @@ @@ @@@@@@@@@@ @@@@ @@@@ @@@@@@@@@@ @@ @@ @@ @@ @@ @@ @@@@@@@@@@ @@ @@@@@@ @@@@@@ @@ @@@@ @@@@ @@ @@@@ @@@@ @@ @@@@ @@@@ @@ @@@@ @@@@@@ @@ @@@@@@ @@ @@ @@@@@@@@ @@ @@@@@@@@@@@@ @@@@@@ @@@@ @@@@@@@@@@ @@@@ @@ @@@@@@@@ @@ @@@@@@ @@ @@ @@@@ @@ @@@@ @@ @@@@ @@@@@@ @@ @@ @@ @@ @@ @@ @@@@@@@@@@ @@ @@ @@ @@ @@@@ @@@@ @@ @@@@ @@ @@@@@@@@@@ @@ @@@@@@ @@ @@@@@@@@@@@@@@@@@@ @@ @@ @@ @@@@@@@@@@ @@@@@@ @@ @@@@@@ @@ @@@@@@@@ @@ @@ @@@@@@@@@@ @@ @@ @@@@@@@@@@ @@ @@@@@@@@@@ @@@@ @@@@ @@ @@@@ @@@@@@ @@ @@ @@ @@ @@ @@@@@@@@@@ @@ @@ @@@@@@ @@@@@@ @@ @@ @@ @@ @@@@@@ @@ @@ @@ @@ @@@@@@@@@@@@@@@@ @@ @@ @@ @@ @@@@ @@@@ @@ @@@@ @@@@ @@@@@@@@ @@ @@@@@@@@@@ @@ @@ @@@@@@@@@@ @@ @@@@@@@@@@@@ @@ @@ @@ @@ @@@@ @@ @@ @@@@@@ @@ @@@@@@ @@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ### Scanlines # zpng --scanlines qr_rgb.png # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ### Palette # zpng --palette qr_plte_bw.png color #0: ff ff ff |...| color #1: 00 00 00 |...| ## Image manipulation #!/usr/bin/env ruby require 'zpng' include ZPNG img = Image.new(File.join(File.dirname(__FILE__),"http.png")) puts "[.] original:" puts img.to_s puts img.width.times do |x| img[x,0] = (x % 2 == 0) ? Color::WHITE : Color::BLACK end puts "[.] modified:" puts img.to_s File.open("http-modified.png","wb") do |f| f << img.export end ## Create 16x16 transparent PNG #!/usr/bin/env ruby require 'zpng' include ZPNG img = Image.new :width => 16, :height => 16 File.open("16x16.png","wb") do |f| f << img.export end License ------- Released under the MIT License. See the [LICENSE](https://github.com/zed-0xff/zpng/blob/master/LICENSE.txt) file for further details.