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.

@see www.w3.org/TR/PNG/#11IHDR

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
127 def initialize(attrs = {})
128   super("IHDR", attrs)
129   @depth       ||= 8
130   @color       ||= ChunkyPNG::COLOR_TRUECOLOR
131   @compression ||= ChunkyPNG::COMPRESSION_DEFAULT
132   @filtering   ||= ChunkyPNG::FILTERING_DEFAULT
133   @interlace   ||= ChunkyPNG::INTERLACING_NONE
134 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
142 def self.read(type, content)
143   fields = content.unpack("NNC5")
144   new(
145     width: fields[0],
146     height: fields[1],
147     depth: fields[2],
148     color: fields[3],
149     compression: fields[4],
150     filtering: fields[5],
151     interlace: fields[6]
152   )
153 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
158 def content
159   [
160     width,
161     height,
162     depth,
163     color,
164     compression,
165     filtering,
166     interlace,
167   ].pack("NNC5")
168 end