Blendend.Canvas.Mask (blendend v0.3.3)

Copy Markdown View Source

Experimental masking helpers for Blendend.Canvas.

Examples

alias Blendend.{Canvas, Canvas.Mask, Style.Color, Image}
mask = Image.from_file_a8!("priv/images/splash.png", :red)
{mw, mh} = Image.size!(mask)

canvas =
Canvas.new!(mw, mh)
|> Canvas.clear!()

:ok =
Mask.fill(canvas, mask, 0, 0,
  color: Color.rgb!(255, 200, 255),
  alpha: 1.0
)

:ok = Canvas.save!(canvas, "priv/images/masked_canvas.png")

To blur a mask (e.g. soft shadows), use blur_fill/6 and set sigma in pixels. A sigma of 3.0 produces a visible blur radius around ~9 px.

Summary

Functions

Blurs a mask image with sigma and fills it at {x, y}.

Same as blur_fill/6, but raises and returns the canvas on success.

Fills using the current style through an image mask anchored at {x, y}. x and y are numbers.

Same as fill/5, but raises Blendend.Error on failure and returns the canvas for use in pipelines.

Types

canvas()

@type canvas() :: Blendend.Canvas.t()

image()

@type image() :: Blendend.Image.t()

Functions

blur_fill(canvas, img, x, y, sigma, opts \\ [])

@spec blur_fill(canvas(), image(), number(), number(), number(), keyword()) ::
  :ok | {:error, term()}

Blurs a mask image with sigma and fills it at {x, y}.

Returns :ok on success or {:error, reason}. Uses the same options as fill/5.

blur_fill!(canvas, img, x, y, sigma, opts \\ [])

@spec blur_fill!(canvas(), image(), number(), number(), number(), keyword()) ::
  canvas()

Same as blur_fill/6, but raises and returns the canvas on success.

fill(canvas, img, x, y, opts \\ [])

@spec fill(canvas(), image(), number(), number(), keyword()) :: :ok | {:error, term()}

Fills using the current style through an image mask anchored at {x, y}. x and y are numbers.

On success returns :ok. On failure returns {:error, reason}.

fill!(canvas, img, x, y, opts \\ [])

@spec fill!(canvas(), image(), number(), number(), keyword()) :: canvas()

Same as fill/5, but raises Blendend.Error on failure and returns the canvas for use in pipelines.