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)
-
- (Object) color
Returns the value of attribute color.
-
- (Object) compression
Returns the value of attribute compression.
-
- (Object) depth
Returns the value of attribute depth.
-
- (Object) filtering
Returns the value of attribute filtering.
-
- (Object) height
Returns the value of attribute height.
-
- (Object) interlace
Returns the value of attribute interlace.
-
- (Object) width
Returns the value of attribute width.
Attributes inherited from Base
Class Method Summary (collapse)
-
+ (ChunkyPNG::Chunk::End) read(type, content)
Reads the 13 bytes of content from the header chunk to set the image attributes.
Instance Method Summary (collapse)
-
- (String) content
Returns the content for this chunk when it gets written to a file, by packing the image information variables into the correct format.
-
- (Header) initialize(attrs = {})
constructor
A new instance of Header.
Methods inherited from Base
Constructor Details
- (Header) initialize(attrs = {})
A new instance of Header
119 120 121 122 123 124 125 126 |
# File 'lib/chunky_png/chunk.rb', line 119 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
- (Object) color
Returns the value of attribute color
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def color @color end |
- (Object) compression
Returns the value of attribute compression
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def compression @compression end |
- (Object) depth
Returns the value of attribute depth
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def depth @depth end |
- (Object) filtering
Returns the value of attribute filtering
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def filtering @filtering end |
- (Object) height
Returns the value of attribute height
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def height @height end |
- (Object) interlace
Returns the value of attribute interlace
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def interlace @interlace end |
- (Object) width
Returns the value of attribute width
117 118 119 |
# File 'lib/chunky_png/chunk.rb', line 117 def width @width end |
Class Method Details
+ (ChunkyPNG::Chunk::End) read(type, content)
Reads the 13 bytes of content from the header chunk to set the image attributes.
133 134 135 136 137 |
# File 'lib/chunky_png/chunk.rb', line 133 def self.read(type, content) fields = content.unpack('NNC5') self.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
- (String) content
Returns the content for this chunk when it gets written to a file, by packing the image information variables into the correct format.
142 143 144 |
# File 'lib/chunky_png/chunk.rb', line 142 def content [width, height, depth, color, compression, filtering, interlace].pack('NNC5') end |