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

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

Methods

Color   Dimension   Point   Vector  

Classes and Modules

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

Constants

VERSION = "1.2.6"   The current version of ChunkyPNG. This value will be updated automatically by them gem:release rake task.
COLOR_GRAYSCALE = 0   Indicates that the PNG image uses grayscale colors, i.e. only a single teint channel. @private
COLOR_TRUECOLOR = 2   Indicates that the PNG image uses true color, composed of a red green and blue channel. @private
COLOR_INDEXED = 3   Indicates that the PNG image uses indexed colors, where the values point to colors defined on a palette. @private
COLOR_GRAYSCALE_ALPHA = 4   Indicates that the PNG image uses grayscale colors with opacity, i.e. a teint channel with an alpha channel. @private
COLOR_TRUECOLOR_ALPHA = 6   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 = 0   Indicates that the PNG specification‘s default compression method is used (Zlib/Deflate) @private
INTERLACING_NONE = 0   Indicates that the image does not use interlacing. @private
INTERLACING_ADAM7 = 1   Indicates that the image uses Adam7 interlacing. @private
FILTERING_DEFAULT = 0   Indicates that the PNG specification‘s default filtering are being used in the image. @private
FILTER_NONE = 0   Indicates that no filtering is used for the scanline. @private
FILTER_SUB = 1   Indicates that SUB filtering is used for the scanline. @private
FILTER_UP = 2   Indicates that UP filtering is used for the scanline. @private
FILTER_AVERAGE = 3   Indicates that AVERAGE filtering is used for the scanline. @private
FILTER_PAETH = 4   Indicates that PAETH filtering is used for the scanline. @private
EMPTY_BYTEARRAY = String.method_defined?(:force_encoding) ? "".force_encoding('ASCII-8BIT').freeze : "".freeze   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 = String.method_defined?(:force_encoding) ? "\0".force_encoding('ASCII-8BIT') : "\0"   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

Public Class methods

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

[Source]

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

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

[Source]

    # File lib/chunky_png/dimension.rb, line 30
30:   def self.Dimension(*args)
31: 
32:     case args.length
33:       when 2; ChunkyPNG::Dimension.new(*args)
34:       when 1; case source = args.first
35:           when ChunkyPNG::Dimension; source
36:           when ChunkyPNG::Point; ChunkyPNG::Dimension.new(source.x, source.y)
37:           when Array; ChunkyPNG::Dimension.new(source[0], source[1])
38:           when Hash;  ChunkyPNG::Dimension.new(source[:width] || source['width'], source[:height] || source['height'])
39:           when ChunkyPNG::Dimension::DIMENSION_REGEXP; ChunkyPNG::Dimension.new($1, $2)
40:           else
41:             if source.respond_to?(:width) && source.respond_to?(:height)
42:               ChunkyPNG::Dimension.new(source.width, source.height)
43:             else
44:               raise ArgumentError, "Don't know how to construct a point from #{source.inspect}!"
45:             end
46:         end
47:       else raise ArgumentError, "Don't know how to construct a point from #{args.inspect}!"
48:     end
49:   end

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

[Source]

    # File lib/chunky_png/point.rb, line 31
31:   def self.Point(*args)
32:     case args.length
33:       when 2; ChunkyPNG::Point.new(*args)
34:       when 1; case source = args.first
35:           when ChunkyPNG::Point; source
36:           when ChunkyPNG::Dimension; ChunkyPNG::Point.new(source.width, source.height)
37:           when Array; ChunkyPNG::Point.new(source[0], source[1])
38:           when Hash; ChunkyPNG::Point.new(source[:x] || source['x'], source[:y] || source['y'])
39:           when ChunkyPNG::Point::POINT_REGEXP; ChunkyPNG::Point.new($1.to_i, $2.to_i)
40:           else 
41:             if source.respond_to?(:x) && source.respond_to?(:y)
42:               ChunkyPNG::Point.new(source.x, source.y)
43:             else
44:               raise ArgumentError, "Don't know how to construct a point from #{source.inspect}!"
45:             end
46:         end
47:       else raise ArgumentError, "Don't know how to construct a point from #{args.inspect}!"
48:     end
49:   end

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

[Source]

    # File lib/chunky_png/vector.rb, line 19
19:   def self.Vector(*args)
20:     
21:     return args.first if args.length == 1 && args.first.kind_of?(ChunkyPNG::Vector)
22:     
23:     if args.length == 1 && args.first.respond_to?(:scan)
24:       ChunkyPNG::Vector.new(ChunkyPNG::Vector.multiple_from_string(args.first)) # e.g. ['1,1 2,2 3,3']
25:     else
26:       ChunkyPNG::Vector.new(ChunkyPNG::Vector.multiple_from_array(args)) # e.g. [[1,1], [2,2], [3,3]] or [1,1,2,2,3,3]
27:     end
28:   end

[Validate]