Skip to content

Instantly share code, notes, and snippets.

@wvanbergen
Created May 24, 2012 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wvanbergen/2780177 to your computer and use it in GitHub Desktop.
Save wvanbergen/2780177 to your computer and use it in GitHub Desktop.
Extract properties from PNG file.
require 'chunky_png'
filename = 'image.png'
img = ChunkyPNG::Datastream.from_file(filename)
# The header chunk contains the information you are looking for
p img.header_chunk
# => #<ChunkyPNG::Chunk::Header:0x007fb3858a50f8 @type="IHDR", @width=8, @height=8, @depth=8, @color=3, @compression=0, @filtering=0, @interlace=1>
puts img.header_chunk.depth # bit depth per color channel, e.g. 8 (i.e. 24 bits for RGB, 32 bits for RGBA)
puts img.header_chunk.color # color mode, e.g. 3 (indexed colors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment