Class: ChunkyPNG::Chunk::Header
Overview
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.
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#compression ⇒ Object
Returns the value of attribute compression.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#filtering ⇒ Object
Returns the value of attribute filtering.
-
#height ⇒ Object
Returns the value of attribute height.
-
#interlace ⇒ Object
Returns the value of attribute interlace.
-
#width ⇒ Object
Returns the value of attribute width.
Attributes inherited from Base
Class Method Summary collapse
-
.read(type, content) ⇒ ChunkyPNG::Chunk::End
Reads the 13 bytes of content from the header chunk to set the image attributes.
Instance Method Summary collapse
-
#content ⇒ String
Returns the content for this chunk when it gets written to a file, by packing the image information variables into the correct format.
-
#initialize(attrs = {}) ⇒ Header
constructor
A new instance of Header.
Methods inherited from Base
Constructor Details
#initialize(attrs = {}) ⇒ Header
Returns a new instance of Header.
124 125 126 127 128 129 130 131 |
# File 'lib/chunky_png/chunk.rb', line 124 def initialize(attrs = {}) super('IHDR', attrs) @depth ||= 8 @color ||= ChunkyPNG::COLOR_TRUECOLOR @compression ||= ChunkyPNG::COMPRESSION_DEFAULT @filtering ||= ChunkyPNG::FILTERING_DEFAULT @interlace ||= ChunkyPNG::INTERLACING_NONE end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def color @color end |
#compression ⇒ Object
Returns the value of attribute compression.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def compression @compression end |
#depth ⇒ Object
Returns the value of attribute depth.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def depth @depth end |
#filtering ⇒ Object
Returns the value of attribute filtering.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def filtering @filtering end |
#height ⇒ Object
Returns the value of attribute height.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def height @height end |
#interlace ⇒ Object
Returns the value of attribute interlace.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def interlace @interlace end |
#width ⇒ Object
Returns the value of attribute width.
121 122 123 |
# File 'lib/chunky_png/chunk.rb', line 121 def width @width end |
Class Method Details
.read(type, content) ⇒ ChunkyPNG::Chunk::End
Reads the 13 bytes of content from the header chunk to set the image attributes.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/chunky_png/chunk.rb', line 139 def self.read(type, content) fields = content.unpack('NNC5') new(:width => fields[0], :height => fields[1], :depth => fields[2], :color => fields[3], :compression => fields[4], :filtering => fields[5], :interlace => fields[6]) end |
Instance Method Details
#content ⇒ String
Returns the content for this chunk when it gets written to a file, by packing the image information variables into the correct format.
153 154 155 156 |
# File 'lib/chunky_png/chunk.rb', line 153 def content [width, height, depth, color, compression, filtering, interlace]. pack('NNC5') end |