Module: ChunkyPNG

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

Overview

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.

Image

class to represent PNG images, including metadata.

Canvas

class to represent the image's canvas.

Color

module to work with color values.

Palette

represents the palette of colors used on a Canvas.

Datastream

represents the internal structure of a PNG Image.

Color

represents one chunk of data within a Datastream.

Point

geometry helper class representing a 2-dimensional point.

Dimension

geometry helper class representing a dimension (i.e. width x height).

Vector

geometry helper class representing a series of points.

Author:

  • Willem van Bergen

Defined Under Namespace

Modules: Chunk, Color, RMagick Classes: CRCMismatch, Canvas, Datastream, Dimension, Exception, ExpectationFailed, Image, NotSupported, OutOfBounds, Palette, Point, SignatureMismatch, Vector

Constant Summary

VERSION =

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

"1.3.1"

Class Method Summary collapse

Class Method Details

.Color(r, g, b, a) ⇒ Integer .Color(r, g, b) ⇒ Integer .Color(hex_value, opacity = nil) ⇒ Integer .Color(color_name, opacity = nil) ⇒ Integer .Color(color_value, opacity = nil) ⇒ Integer

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

Raises:

  • (ArgumentError)

    if the arguments weren't understood as a color.

See Also:

  • Color
  • ChunkyPNG::Color.parse


32
33
34
35
36
37
38
39
40
# 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(width, height) ⇒ ChunkyPNG::Dimension .Dimension(string) ⇒ ChunkyPNG::Dimension .Dimension(ary) ⇒ ChunkyPNG::Dimension .Dimension(hash) ⇒ ChunkyPNG::Dimension

Creates a Dimension instance using arguments that can be interpreted as width and height.

Raises:

  • (ArgumentError)

    If the argument(s) given where not understood as a dimension.

See Also:



30
31
32
33
34
35
36
37
# 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

.force_binary(str) ⇒ Object



124
125
126
# File 'lib/chunky_png.rb', line 124

def self.force_binary(str)
  str.respond_to?(:force_encoding) ? str.force_encoding('BINARY') : str
end

.Point(x, y) ⇒ ChunkyPNG::Point .Point(array) ⇒ ChunkyPNG::Point .Point(hash) ⇒ ChunkyPNG::Point .Point(string) ⇒ ChunkyPNG::Point

Factory method to create 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, Dimension instances and anything that responds to :x and :y.

Raises:

  • (ArgumentError)

    if the arguments weren't understood.

See Also:



31
32
33
34
35
36
37
38
# 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(x0, y0, x1, y1, x2, y2, ...) ⇒ ChunkyPNG::Vector .Vector(string) ⇒ ChunkyPNG::Vector .Vector(pointlike, pointlike, pointlike, ...) ⇒ ChunkyPNG::Vector

Factory method for Vector instances.

Overloads:

  • .Vector(x0, y0, x1, y1, x2, y2, ...) ⇒ ChunkyPNG::Vector

    Creates a vector by parsing two subsequent values in the argument list as x- and y-coordinate of a point.

  • .Vector(string) ⇒ ChunkyPNG::Vector

    Creates a vector by parsing coordinates from the input string.

  • .Vector(pointlike, pointlike, pointlike, ...) ⇒ ChunkyPNG::Vector

    Creates a vector by converting every argument to a point using Point.

Raises:

  • (ArgumentError)

    If the given arguments could not be understood as a vector.

See Also:



19
20
21
22
23
24
25
26
27
28
# 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