module ChunkyPNG

def self.Color(*args)

Other tags:
    See: ChunkyPNG::Color.parse -
    See: ChunkyPNG::Color -

Raises:
  • (ArgumentError) - if the arguments weren't understood as a color.

Returns:
  • (Integer) - The determined color value as RGBA integer.
  • (Integer) - The color value, with the opacity applied if one was given.
  • (Integer) - The hex color value, with the opacity applied if one was given.
  • (Integer) - The hex color value, with the opacity applied if one was given.
  • (Integer) - The rgb color value.
  • (Integer) - The rgba color value.

Parameters:
  • The (Integer, :to_i) -- color value.
  • () --
  • () --
  • () --
  • () --

Overloads:
  • Color(color_value, opacity = nil)
  • Color(color_name, opacity = nil)
  • Color(hex_value, opacity = nil)
  • Color(r, g, b)
  • Color(r, g, b, a)
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

def self.Dimension(*args)

Other tags:
    See: ChunkyPNG::Dimension -

Raises:
  • (ArgumentError) - If the argument(s) given where not understood as a dimension.

Returns:
  • (ChunkyPNG::Dimension) - The dimension created by this factory method.
  • (ChunkyPNG::Dimension) - The instantiated dimension.
  • (ChunkyPNG::Dimension) - The instantiated dimension.
  • (ChunkyPNG::Dimension) - The instantiated dimension.
  • (ChunkyPNG::Dimension) - The instantiated dimension.

Parameters:
  • hash (Hash) -- An hash with a 'height' or :height key for the
  • ary (Array) -- An array with the desired width as first element and the
  • string (String) -- A string from which a width and height value can be parsed, e.g.
  • height (Integer) -- The height-component of the dimension.
  • width (Integer) -- The width-component of the dimension.

Overloads:
  • Dimension(hash)
  • Dimension(ary)
  • Dimension(string)
  • Dimension(width, height)
def self.Dimension(*args)
  case args.length
    when 2; ChunkyPNG::Dimension.new(*args)
    when 1; case source = args.first
        when ChunkyPNG::Dimension; source
        when ChunkyPNG::Point; ChunkyPNG::Dimension.new(source.x, source.y)
        when Array; ChunkyPNG::Dimension.new(source[0], source[1])
        when Hash;  ChunkyPNG::Dimension.new(source[:width] || source['width'], source[:height] || source['height'])
        when ChunkyPNG::Dimension::DIMENSION_REGEXP; ChunkyPNG::Dimension.new($1, $2)
        else
          if source.respond_to?(:width) && source.respond_to?(:height)
            ChunkyPNG::Dimension.new(source.width, source.height)
          else
            raise ArgumentError, "Don't know how to construct a point from #{source.inspect}!"
          end
      end
    else raise ArgumentError, "Don't know how to construct a point from #{args.inspect}!"
  end
end

def self.Point(*args)

Other tags:
    See: ChunkyPNG::Point -

Raises:
  • (ArgumentError) - if the arguments weren't understood.

Returns:
  • (ChunkyPNG::Point) -
  • (ChunkyPNG::Point) - The instantiated point.
  • (ChunkyPNG::Point) - The instantiated point.
  • (ChunkyPNG::Point) - The instantiated point.
  • (ChunkyPNG::Point) - The instantiated point.

Parameters:
  • string (String) -- A string that contains the coordinates, e.g. '0, 4',
  • array (Hash) -- A hash with the :x or 'x' and :y or
  • array (Array) -- A two element array which represent the x- and y-coordinate.
  • y (Integer, :to_i) -- The y-coordinate
  • x (Integer, :to_i) -- The x-coordinate

Overloads:
  • Point(string)
  • Point(hash)
  • Point(array)
  • Point(x, y)
def self.Point(*args)
  case args.length
    when 2; ChunkyPNG::Point.new(*args)
    when 1; case source = args.first
        when ChunkyPNG::Point; source
        when ChunkyPNG::Dimension; ChunkyPNG::Point.new(source.width, source.height)
        when Array; ChunkyPNG::Point.new(source[0], source[1])
        when Hash; ChunkyPNG::Point.new(source[:x] || source['x'], source[:y] || source['y'])
        when ChunkyPNG::Point::POINT_REGEXP; ChunkyPNG::Point.new($1.to_i, $2.to_i)
        else 
          if source.respond_to?(:x) && source.respond_to?(:y)
            ChunkyPNG::Point.new(source.x, source.y)
          else
            raise ArgumentError, "Don't know how to construct a point from #{source.inspect}!"
          end
      end
    else raise ArgumentError, "Don't know how to construct a point from #{args.inspect}!"
  end
end

def self.Vector(*args)

Other tags:
    See: ChunkyPNG::Vector -

Raises:
  • (ArgumentError) - If the given arguments could not be understood as a vector.

Returns:
  • (ChunkyPNG::Vector) - The vector created by this factory method.
  • (ChunkyPNG::Vector) - The instantiated vector.
  • (ChunkyPNG::Vector) - The instantiated vector.
  • (ChunkyPNG::Vector) - The instantiated vector.

Overloads:
  • Vector(pointlike, pointlike, pointlike, ...)
  • Vector(string)
  • Vector(x0, y0, x1, y1, x2, y2, ...)
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

def self.force_binary(str)

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