module ChunkyPNG

def self.Color(*args) # rubocop:disable Naming/MethodName # API backwards compatibility

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
  • (Integer) - The hex color value, with the opacity applied if one
  • (Integer) - The hex color value, with the opacity applied if one
  • (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) # rubocop:disable Naming/MethodName # API backwards compatibility
  case args.length
    when 1 then ChunkyPNG::Color.parse(args.first)
    when 2 then (ChunkyPNG::Color.parse(args.first) & 0xffffff00) | args[1].to_i
    when 3 then ChunkyPNG::Color.rgb(*args)
    when 4 then 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 then ChunkyPNG::Dimension.new(*args)
  when 1 then build_dimension_from_object(args.first)
  else raise ArgumentError,
    "Don't know how to construct a dimension 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 then ChunkyPNG::Point.new(*args)
  when 1 then build_point_from_object(args.first)
  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.is_a?(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.build_dimension_from_object(source)

def self.build_dimension_from_object(source)
  case source
  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
    width = source[:width] || source["width"]
    height = source[:height] || source["height"]
    ChunkyPNG::Dimension.new(width, 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 dimension from #{source.inspect}!"
    end
  end
end

def self.build_point_from_object(source)

def self.build_point_from_object(source)
  case source
  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
    x = source[:x] || source["x"]
    y = source[:y] || source["y"]
    ChunkyPNG::Point.new(x, 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
end