Module: ChunkyPNG

### Home Classes Methods

### In Files

- lib/chunky_png.rb
- lib/chunky_png/canvas.rb
- lib/chunky_png/canvas/adam7_interlacing.rb
- lib/chunky_png/canvas/data_url_exporting.rb
- lib/chunky_png/canvas/data_url_importing.rb
- lib/chunky_png/canvas/drawing.rb
- lib/chunky_png/canvas/masking.rb
- lib/chunky_png/canvas/operations.rb
- lib/chunky_png/canvas/png_decoding.rb
- lib/chunky_png/canvas/png_encoding.rb
- lib/chunky_png/canvas/resampling.rb
- lib/chunky_png/canvas/stream_exporting.rb
- lib/chunky_png/canvas/stream_importing.rb
- lib/chunky_png/chunk.rb
- lib/chunky_png/color.rb
- lib/chunky_png/datastream.rb
- lib/chunky_png/dimension.rb
- lib/chunky_png/image.rb
- lib/chunky_png/palette.rb
- lib/chunky_png/point.rb
- lib/chunky_png/rmagick.rb
- lib/chunky_png/vector.rb
- lib/chunky_png/version.rb

### Namespace

- MODULE ChunkyPNG::Chunk
- MODULE ChunkyPNG::Color
- MODULE ChunkyPNG::RMagick
- CLASS ChunkyPNG::CRCMismatch
- CLASS ChunkyPNG::Canvas
- CLASS ChunkyPNG::Datastream
- CLASS ChunkyPNG::Dimension
- CLASS ChunkyPNG::Exception
- CLASS ChunkyPNG::ExpectationFailed
- CLASS ChunkyPNG::Image
- CLASS ChunkyPNG::NotSupported
- CLASS ChunkyPNG::OutOfBounds
- CLASS ChunkyPNG::Palette
- CLASS ChunkyPNG::Point
- CLASS ChunkyPNG::SignatureMismatch
- CLASS ChunkyPNG::Vector

### Methods

- ::Color
- ::Dimension
- ::Point
- ::Vector
- ::force_binary

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

ChunkyPNG - the pure ruby library to access PNG files.

The ChunkyPNG module defines some constants that are used in the PNG specification, specifies some exception classes, and serves as a namespace for all the other modules and classes in this library.

{ChunkyPNG::Image} | class to represent PNG images, including metadata.
{ChunkyPNG::Canvas} | class to represent the image's canvas.
{ChunkyPNG::Color} | module to work with color values.
{ChunkyPNG::Palette} | represents the palette of colors used on a {ChunkyPNG::Canvas}.
{ChunkyPNG::Datastream} | represents the internal structure of a PNG {ChunkyPNG::Image}.
{ChunkyPNG::Color} | represents one chunk of data within a {ChunkyPNG::Datastream}.
{ChunkyPNG::Point} | geometry helper class representing a 2-dimensional point.
{ChunkyPNG::Dimension} | geometry helper class representing a dimension (i.e. width x height).
{ChunkyPNG::Vector} | geometry helper class representing a series of points.

@author Willem van Bergen

### Constants

COLOR_GRAYSCALE

  Indicates that the PNG image uses grayscale colors, i.e. only a single teint channel. @private

COLOR_GRAYSCALE_ALPHA

  Indicates that the PNG image uses grayscale colors with opacity, i.e. a teint channel with an alpha channel. @private

COLOR_INDEXED

  Indicates that the PNG image uses indexed colors, where the values point to colors defined on a palette. @private

COLOR_TRUECOLOR

  Indicates that the PNG image uses true color, composed of a red green and blue channel. @private

COLOR_TRUECOLOR_ALPHA

  Indicates that the PNG image uses true color with opacity, composed of a red, green and blue channel, and an alpha value. @private

COMPRESSION_DEFAULT

  Indicates that the PNG specification's default compression method is used (Zlib/Deflate) @private

EMPTY_BYTEARRAY

  Empty byte array. This basically is an empty string, but with the encoding set correctly to ASCII-8BIT (binary) in Ruby 1.9. @return [String] An empty string, with encoding set to binary in Ruby 1.9 @private

EXTRA_BYTE

  Null-byte, with the encoding set correctly to ASCII-8BIT (binary) in Ruby 1.9. @return [String] A binary string, consisting of one NULL-byte. @private

FILTERING_DEFAULT

  Indicates that the PNG specification's default filtering are being used in the image. @private

FILTER_AVERAGE

  Indicates that AVERAGE filtering is used for the scanline. @private

FILTER_NONE

  Indicates that no filtering is used for the scanline. @private

FILTER_PAETH

  Indicates that PAETH filtering is used for the scanline. @private

FILTER_SUB

  Indicates that SUB filtering is used for the scanline. @private

FILTER_UP

  Indicates that UP filtering is used for the scanline. @private

INTERLACING_ADAM7

  Indicates that the image uses Adam7 interlacing. @private

INTERLACING_NONE

  Indicates that the image does not use interlacing. @private

VERSION

  The current version of ChunkyPNG. Set it and commit the change this before running rake release.

### Public Class Methods

Color(*args) click to toggle source

Factory method to return a color value, based on the arguments given.

@overload Color(r, g, b, a)

    @param (see ChunkyPNG::Color.rgba)
    @return [Integer] The rgba color value.

@overload Color(r, g, b)

    @param (see ChunkyPNG::Color.rgb)
    @return [Integer] The rgb color value.

@overload Color(hex_value, opacity = nil)

    @param (see ChunkyPNG::Color.from_hex)
    @return [Integer] The hex color value, with the opacity applied if one
      was given.

@overload Color(color_name, opacity = nil)

    @param (see ChunkyPNG::Color.html_color)
    @return [Integer] The hex color value, with the opacity applied if one
      was given.

@overload Color(color_value, opacity = nil)

    @param [Integer, :to_i] The color value.
    @return [Integer] The color value, with the opacity applied if one was
      given.

@return [Integer] The determined color value as RGBA integer. @raise [ArgumentError] if the arguments weren't understood as a color. @see ChunkyPNG::Color @see ChunkyPNG::Color.parse

    # File lib/chunky_png/color.rb, line 32
    def self.Color(*args)
      case args.length
        when 1; ChunkyPNG::Color.parse(args.first)
        when 2; (ChunkyPNG::Color.parse(args.first) & 0xffffff00) | args[1].to_i
        when 3; ChunkyPNG::Color.rgb(*args)
        when 4; ChunkyPNG::Color.rgba(*args)
        else raise ArgumentError, "Don't know how to create a color from #{args.inspect}!"
      end
    end

Dimension(*args) click to toggle source

Creates a {ChunkyPNG::Dimension} instance using arguments that can be interpreted as width and height.

@overload Dimension(width, height)

    @param [Integer] width The width-component of the dimension.
    @param [Integer] height The height-component of the dimension.
    @return [ChunkyPNG::Dimension] The instantiated dimension.

@overload Dimension(string)

    @param [String] string A string from which a width and height value can be parsed, e.g.
       <tt>'10x20'</tt> or <tt>'[10, 20]'</tt>.
    @return [ChunkyPNG::Dimension] The instantiated dimension.

@overload Dimension(ary)

    @param [Array] ary An array with the desired width as first element and the
       desired height as second element, e.g. <tt>[10, 20]</tt>.
    @return [ChunkyPNG::Dimension] The instantiated dimension.

@overload Dimension(hash)

    @param [Hash] hash An hash with a <tt>'height'</tt> or <tt>:height</tt> key for the
       desired height and with a <tt>'width'</tt> or <tt>:width</tt> key for the desired
       width.
    @return [ChunkyPNG::Dimension] The instantiated dimension.

@return [ChunkyPNG::Dimension] The dimension created by this factory method. @raise [ArgumentError] If the argument(s) given where not understood as a dimension. @see ChunkyPNG::Dimension

    # File lib/chunky_png/dimension.rb, line 30
    def self.Dimension(*args)
      case args.length
      when 2; ChunkyPNG::Dimension.new(*args)
      when 1; build_dimension_from_object(args.first)
      else raise ArgumentError,
        "Don't know how to construct a dimension from #{args.inspect}"
      end
    end

Point(*args) click to toggle source

Factory method to create {ChunkyPNG::Point} instances.

This method tries to be as flexible as possible with regards to the given input: besides explicit coordinates, this method also accepts arrays, hashes, strings, {ChunkyPNG::Dimension} instances and anything that responds to `:x` and `:y`.

@overload Point(x, y)

    @param [Integer, :to_i] x The x-coordinate
    @param [Integer, :to_i] y The y-coordinate
    @return [ChunkyPNG::Point] The instantiated point.

@overload Point(array)

    @param [Array<Integer>] array A two element array which represent the x- and y-coordinate.
    @return [ChunkyPNG::Point] The instantiated point.

@overload Point(hash)

    @param [Hash] array A hash with the <tt>:x</tt> or <tt>'x'</tt> and <tt>:y</tt> or
      <tt>'y'</tt> keys set, which will be used as coordinates.
    @return [ChunkyPNG::Point] The instantiated point.

@overload Point(string)

    @param [String] string A string that contains the coordinates, e.g. <tt>'0, 4'</tt>,
      <tt>'(0 4)'</tt>, <tt>[0,4}'</tt>, etc.
    @return [ChunkyPNG::Point] The instantiated point.

@return [ChunkyPNG::Point] @raise [ArgumentError] if the arguments weren't understood. @see ChunkyPNG::Point

    # File lib/chunky_png/point.rb, line 31
    def self.Point(*args)
      case args.length
      when 2; ChunkyPNG::Point.new(*args)
      when 1; build_point_from_object(args.first)
      else raise ArgumentError,
        "Don't know how to construct a point from #{args.inspect}!"
      end
    end

Vector(*args) click to toggle source

Factory method for {ChunkyPNG::Vector} instances.

@overload Vector(x0, y0, x1, y1, x2, y2, ...)

    Creates a vector by parsing two subsequent values in the argument list
    as x- and y-coordinate of a point.
    @return [ChunkyPNG::Vector] The instantiated vector.

@overload Vector(string)

    Creates a vector by parsing coordinates from the input string.
    @return [ChunkyPNG::Vector] The instantiated vector.

@overload Vector(pointlike, pointlike, pointlike, ...)

    Creates a vector by converting every argument to a point using {ChunkyPNG.Point}.
    @return [ChunkyPNG::Vector] The instantiated vector.

@return [ChunkyPNG::Vector] The vector created by this factory method. @raise [ArgumentError] If the given arguments could not be understood as a vector. @see ChunkyPNG::Vector

    # File lib/chunky_png/vector.rb, line 19
    def self.Vector(*args)

      return args.first if args.length == 1 && args.first.kind_of?(ChunkyPNG::Vector)

      if args.length == 1 && args.first.respond_to?(:scan)
        ChunkyPNG::Vector.new(ChunkyPNG::Vector.multiple_from_string(args.first)) # e.g. ['1,1 2,2 3,3']
      else
        ChunkyPNG::Vector.new(ChunkyPNG::Vector.multiple_from_array(args)) # e.g. [[1,1], [2,2], [3,3]] or [1,1,2,2,3,3]
      end
    end

force_binary(str) click to toggle source

    # File lib/chunky_png.rb, line 124
    def self.force_binary(str)
      str.respond_to?(:force_encoding) ? str.force_encoding('BINARY') : str
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.