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
124 def initialize(attrs = {})
125   super('IHDR', attrs)
126   @depth       ||= 8
127   @color       ||= ChunkyPNG::COLOR_TRUECOLOR
128   @compression ||= ChunkyPNG::COMPRESSION_DEFAULT
129   @filtering   ||= ChunkyPNG::FILTERING_DEFAULT
130   @interlace   ||= ChunkyPNG::INTERLACING_NONE
131 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
139 def self.read(type, content)
140   fields = content.unpack('NNC5')
141   new(: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 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
153 def content
154   [width, height, depth, color, compression, filtering, interlace].
155     pack('NNC5')
156 end