View Source Image.BlendMode (image v0.55.2)

Functions to define and validate the blending modes that can be applied when composing images.

Summary

Types

t()

Blend mode to use when compositing images. See Image.compose/3.

Functions

Returns the default blend mode

Returns the known blending modes.

Normalizes and validates a blend mode.

Types

@type t() ::
  :exclusion
  | :soft_light
  | :hard_light
  | :colour_burn
  | :colour_dodge
  | :lighten
  | :darken
  | :screen
  | :saturate
  | :dest_atop
  | :dest_out
  | :dest_in
  | :dest_over
  | :atop
  | :over
  | :overlay
  | :multiply
  | :dest
  | :source
  | :difference
  | :add
  | :xor
  | :out
  | :in
  | :clear

Blend mode to use when compositing images. See Image.compose/3.

  • :over the image shows what you would expect if you held two semi-transparent slides on top of each other. This is the default when composing images
  • :clear where the second image is drawn, the first is removed
  • :source the second image is drawn as if nothing were below
  • :in the first image is removed completely, the second is only drawn where the first was
  • :out the second is drawn only where the first isn't
  • :atop this leaves the first image mostly intact, but mixes both images in the overlapping area
  • :dest leaves the first image untouched, the second is discarded completely
  • :dest_over like :over, but swaps the arguments
  • :dest_in like :in, but swaps the arguments
  • :dest_out like :out, but swaps the arguments
  • :dest_atop like :atop, but swaps the arguments
  • :xor something like a difference operator
  • :add a bit like adding the two images
  • :saturate a bit like the darker of the two
  • :multiply at least as dark as the darker of the two inputs
  • :screen at least as light as the lighter of the inputs
  • :overlay multiplies or screens colors, depending on the lightness
  • :darken the darker of each component
  • :lighten the lighter of each component
  • :colour_dodge brighten first by a factor second
  • :colour_burn darken first by a factor of second
  • :hard_light multiply or screen, depending on lightness
  • :soft_light darken or lighten, depending on lightness
  • :difference difference of the two
  • :exclusion somewhat like :difference, but lower-contrast

Functions

Returns the default blend mode

Example

iex> Image.BlendMode.default_blend_mode
:VIPS_BLEND_MODE_OVER

Returns the known blending modes.

See Image.BlendMode.t/0 for a description of each mode.

Link to this function

validate_blend_mode(blend_mode)

View Source
@spec validate_blend_mode(t() | nil) ::
  {:ok, atom()} | {:error, Image.error_message()}

Normalizes and validates a blend mode.

Argument

Returns

  • {:ok, atom_blend_mode} where atom_blend_mode is a valid blend mode for libvips

  • {:error, reason}

Examples

iex> Image.BlendMode.validate_blend_mode :clear
{:ok, :VIPS_BLEND_MODE_CLEAR}

iex> Image.BlendMode.validate_blend_mode "Over"
{:ok, :VIPS_BLEND_MODE_OVER}

iex> Image.BlendMode.validate_blend_mode :VIPS_BLEND_MODE_XOR
{:ok, :VIPS_BLEND_MODE_XOR}

iex> Image.BlendMode.validate_blend_mode :woops
{:error, {:error, "Unknown blend mode. Found :woops"}}