Image.BackgroundColor (image v0.71.0)

Copy Markdown View Source

Resolves an Image.Pixel.t() / :average value into a concrete pixel in the image's colorspace.

A background color specification is either the atom :average (the average color of the image), or any color accepted by Image.Pixel.to_pixel/2 (a Color struct, a hex string, a CSS named color, an atom or a list of numbers).

In both cases the resolved pixel matches image's number of bands.

Summary

Types

A background color specification: the image's average color, or any color.

Functions

Resolves a background color spec into a pixel matching image's interpretation and band layout.

Types

spec()

@type spec() :: Image.Pixel.t() | :average

A background color specification: the image's average color, or any color.

Functions

resolve(image, color)

@spec resolve(Vix.Vips.Image.t(), spec()) ::
  {:ok, [number()]} | {:error, Image.Error.t()}

Resolves a background color spec into a pixel matching image's interpretation and band layout.

Arguments

Returns

  • {:ok, [number()]} - the resolved pixel, whose band count matches image (an opaque alpha band is appended for :average when the image has alpha), or

  • {:error, t:Image.Error.t/0}

Examples

iex> image = Image.new!(3, 3, color: :red)
iex> Image.BackgroundColor.resolve(image, :average)
{:ok, [255, 0, 0]}
iex> Image.BackgroundColor.resolve(image, :blue)
{:ok, [0, 0, 255]}
iex> Image.BackgroundColor.resolve(image, "#00ff00")
{:ok, [0, 255, 0]}