Class: ChunkyPNG::Chunk::Header

### Home Classes Methods

### In Files

- lib/chunky_png/chunk.rb

### Parent

ChunkyPNG::Chunk::Base

### Methods

- ::new
- ::read
- #content

### Files

- BENCHMARKING.rdoc
- CHANGELOG.rdoc
- CONTRIBUTING.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ChunkyPNG
- ChunkyPNG::CRCMismatch
- ChunkyPNG::Canvas
- ChunkyPNG::Canvas::Adam7Interlacing
- ChunkyPNG::Canvas::DataUrlExporting
- ChunkyPNG::Canvas::DataUrlImporting
- ChunkyPNG::Canvas::Drawing
- ChunkyPNG::Canvas::Masking
- ChunkyPNG::Canvas::Operations
- ChunkyPNG::Canvas::PNGDecoding
- ChunkyPNG::Canvas::PNGEncoding
- ChunkyPNG::Canvas::Resampling
- ChunkyPNG::Canvas::StreamExporting
- ChunkyPNG::Canvas::StreamImporting
- ChunkyPNG::Chunk
- ChunkyPNG::Chunk::Base
- ChunkyPNG::Chunk::CompressedText
- ChunkyPNG::Chunk::End
- ChunkyPNG::Chunk::Generic
- ChunkyPNG::Chunk::Header
- ChunkyPNG::Chunk::ImageData
- ChunkyPNG::Chunk::InternationalText
- ChunkyPNG::Chunk::Palette
- ChunkyPNG::Chunk::Text
- ChunkyPNG::Chunk::Transparency
- ChunkyPNG::Color
- ChunkyPNG::Datastream
- ChunkyPNG::Dimension
- ChunkyPNG::Exception
- ChunkyPNG::ExpectationFailed
- ChunkyPNG::Image
- ChunkyPNG::NotSupported
- ChunkyPNG::OutOfBounds
- ChunkyPNG::Palette
- ChunkyPNG::Point
- ChunkyPNG::RMagick
- ChunkyPNG::SignatureMismatch
- ChunkyPNG::Vector
- Enumerable
- String

No matching classes.

# 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

    # 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

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, 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

### 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, line 153
    def content
      [width, height, depth, color, compression, filtering, interlace].
        pack('NNC5')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.