Class ChunkyPNG::Chunk::Header
In: lib/chunky_png/chunk.rb
Parent: Base

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.

Methods

content   new   read  

Attributes

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

Public Class methods

[Source]

     # File lib/chunky_png/chunk.rb, line 119
119:       def initialize(attrs = {})
120:         super('IHDR', attrs)
121:         @depth       ||= 8
122:         @color       ||= ChunkyPNG::COLOR_TRUECOLOR
123:         @compression ||= ChunkyPNG::COMPRESSION_DEFAULT
124:         @filtering   ||= ChunkyPNG::FILTERING_DEFAULT
125:         @interlace   ||= ChunkyPNG::INTERLACING_NONE
126:       end

Reads the 13 bytes of content from the header chunk to set the image attributes. @param [String] type The four character chunk type indicator (= "IHDR"). @param [String] content 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.

[Source]

     # File lib/chunky_png/chunk.rb, line 133
133:       def self.read(type, content)
134:         fields = content.unpack('NNC5')
135:         self.new(:width => fields[0],  :height => fields[1], :depth => fields[2], :color => fields[3],
136:                        :compression => fields[4], :filtering => fields[5], :interlace => fields[6])
137:       end

Public Instance methods

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.

[Source]

     # File lib/chunky_png/chunk.rb, line 142
142:       def content
143:         [width, height, depth, color, compression, filtering, interlace].pack('NNC5')
144:       end

[Validate]