Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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