class ChunkyPNG::Chunk::Header

The header (IHDR) chunk is the first chunk of every PNG image, and contains information about the image: i.e. its width, height, color depth, color mode, compression method, filtering method and interlace method.

ChunkyPNG supports all values for these variables that are defined in the PNG spec, except for color depth: Only 8-bit depth images are supported. Note that it is still possible to access the chunk for such an image, but ChunkyPNG will raise an exception if you try to access the pixel data.

Attributes

color[RW]
compression[RW]
depth[RW]
filtering[RW]
height[RW]
interlace[RW]
width[RW]

Public Class Methods

new(attrs = {}) click to toggle source
Calls superclass method ChunkyPNG::Chunk::Base::new
    # File lib/chunky_png/chunk.rb
123 def initialize(attrs = {})
124   super("IHDR", attrs)
125   @depth       ||= 8
126   @color       ||= ChunkyPNG::COLOR_TRUECOLOR
127   @compression ||= ChunkyPNG::COMPRESSION_DEFAULT
128   @filtering   ||= ChunkyPNG::FILTERING_DEFAULT
129   @interlace   ||= ChunkyPNG::INTERLACING_NONE
130 end
read(type, content) click to toggle source

Reads the 13 bytes of content from the header chunk to set the image attributes. @param type [String] The four character chunk type indicator (= “IHDR”). @param content [String] The 13 bytes of content read from the chunk. @return [ChunkyPNG::Chunk::End] The new Header chunk instance with the

variables set to the values according to the content.
    # File lib/chunky_png/chunk.rb
138 def self.read(type, content)
139   fields = content.unpack("NNC5")
140   new(
141     width: fields[0],
142     height: fields[1],
143     depth: fields[2],
144     color: fields[3],
145     compression: fields[4],
146     filtering: fields[5],
147     interlace: fields[6]
148   )
149 end

Public Instance Methods

content() click to toggle source

Returns the content for this chunk when it gets written to a file, by packing the image information variables into the correct format. @return [String] The 13-byte content for the header chunk.

    # File lib/chunky_png/chunk.rb
154 def content
155   [
156     width,
157     height,
158     depth,
159     color,
160     compression,
161     filtering,
162     interlace,
163   ].pack("NNC5")
164 end