Created
May 24, 2012 08:14
-
-
Save wvanbergen/2780177 to your computer and use it in GitHub Desktop.
Extract properties from PNG file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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