Batched, immutable drawing documents rendered through Skia.

Build a %Skia.Document{} with pipe-friendly commands, then end the pipeline with a renderer such as to_png/1, to_raw/1, or render/2.

{:ok, png} =
  Skia.canvas(800, 600)
  |> Skia.clear(:white)
  |> Skia.rect(x: 40, y: 40, width: 120, height: 80, fill: :red)
  |> Skia.to_png()

Summary

Functions

Adds a arc command to the document.

Creates an empty drawing document.

Adds a circle command to the document.

Adds a clear command to the document.

Adds a clip_circle command to the document.

Adds a clip_path command to the document.

Adds a clip_rect command to the document.

Returns normalized commands in render order.

Adds a concat command to the document.

Adds a saved canvas group with optional transforms.

Adds a image command to the document.

Adds a saved layer with optional opacity.

Adds a line command to the document.

Measures text using the native text engine.

Adds a oval command to the document.

Adds a path command to the document.

Adds a path_op command to the document.

Adds a path_outline command to the document.

Adds a picture command to the document.

Records the document into a reusable Skia picture.

Adds a rect command to the document.

Renders the document according to Skia.RenderOptions.

Adds a rotate_at command to the document.

Adds a scale command to the document.

Adds a style scope for following commands in the group.

Adds text with optional %Skia.TextStyle{} and %Skia.ParagraphStyle{} values.

Adds a text_blob command to the document.

Encodes the document to the term batch a native renderer would consume.

Renders the document to JPEG through the native renderer.

Renders the document to PNG through the native renderer.

Renders the document to a raw RGBA buffer.

Renders the document to WEBP through the native renderer.

Validates the document before handing it to native code.

Adds a vertices command to the document.

Types

document()

@type document() :: Skia.Document.t()

Functions

arc(document, opts \\ [])

@spec arc(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a arc command to the document.

canvas(width, height)

@spec canvas(pos_integer(), pos_integer()) :: Skia.Document.t()

Creates an empty drawing document.

circle(document, opts \\ [])

@spec circle(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a circle command to the document.

clear(document, color, opts \\ [])

@spec clear(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a clear command to the document.

clip_circle(document, opts \\ [])

@spec clip_circle(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a clip_circle command to the document.

clip_path(document, path, opts \\ [])

@spec clip_path(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a clip_path command to the document.

clip_rect(document, opts \\ [])

@spec clip_rect(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a clip_rect command to the document.

commands(document)

@spec commands(Skia.Document.t()) :: [Skia.Command.t()]

Returns normalized commands in render order.

concat(document, opts \\ [])

@spec concat(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a concat command to the document.

group(document, opts, fun)

Adds a saved canvas group with optional transforms.

image(document, image, opts \\ [])

@spec image(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a image command to the document.

layer(document, opts, fun)

Adds a saved layer with optional opacity.

line(document, opts \\ [])

@spec line(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a line command to the document.

measure_text(text, opts \\ [])

@spec measure_text(
  String.t(),
  keyword()
) ::
  {:ok, %{width: float(), bounds: {float(), float(), float(), float()}}}
  | {:error, atom()}

Measures text using the native text engine.

oval(document, opts \\ [])

@spec oval(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a oval command to the document.

path(document, path, opts \\ [])

@spec path(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a path command to the document.

path_op(document, a, b, opts \\ [])

@spec path_op(Skia.Document.t(), term(), term(), keyword()) :: Skia.Document.t()

Adds a path_op command to the document.

path_outline(document, path, opts \\ [])

@spec path_outline(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a path_outline command to the document.

picture(document, picture, opts \\ [])

@spec picture(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a picture command to the document.

record_picture(document)

@spec record_picture(Skia.Document.t()) ::
  {:ok, Skia.Picture.t()} | {:error, atom(), map()}

Records the document into a reusable Skia picture.

rect(document, opts \\ [])

@spec rect(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a rect command to the document.

render(document, opts \\ [])

@spec render(Skia.Document.t(), keyword() | Skia.RenderOptions.t()) ::
  {:ok, binary() | map()} | {:error, atom(), map()}

Renders the document according to Skia.RenderOptions.

rotate_at(document, opts \\ [])

@spec rotate_at(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a rotate_at command to the document.

scale(document, opts \\ [])

@spec scale(
  Skia.Document.t(),
  keyword()
) :: Skia.Document.t()

Adds a scale command to the document.

style(document, opts, fun)

Adds a style scope for following commands in the group.

text(document, text, opts \\ [])

@spec text(Skia.Document.t(), String.t(), keyword()) :: Skia.Document.t()

Adds text with optional %Skia.TextStyle{} and %Skia.ParagraphStyle{} values.

text_blob(document, blob, opts \\ [])

@spec text_blob(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a text_blob command to the document.

to_batch(document)

@spec to_batch(Skia.Document.t()) :: %{
  width: pos_integer(),
  height: pos_integer(),
  commands: [Skia.Command.t()]
}

Encodes the document to the term batch a native renderer would consume.

to_jpeg(document, opts \\ [])

@spec to_jpeg(
  Skia.Document.t(),
  keyword()
) :: {:ok, binary()} | {:error, atom(), map()}

Renders the document to JPEG through the native renderer.

to_png(document)

@spec to_png(Skia.Document.t()) :: {:ok, binary()} | {:error, atom(), map()}

Renders the document to PNG through the native renderer.

to_raw(document)

@spec to_raw(Skia.Document.t()) ::
  {:ok,
   %{
     width: pos_integer(),
     height: pos_integer(),
     stride: pos_integer(),
     data: binary()
   }}
  | {:error, atom(), map()}

Renders the document to a raw RGBA buffer.

to_webp(document, opts \\ [])

@spec to_webp(
  Skia.Document.t(),
  keyword()
) :: {:ok, binary()} | {:error, atom(), map()}

Renders the document to WEBP through the native renderer.

validate(document)

@spec validate(Skia.Document.t()) :: :ok | {:error, atom(), map()}

Validates the document before handing it to native code.

vertices(document, vertices, opts \\ [])

@spec vertices(Skia.Document.t(), term(), keyword()) :: Skia.Document.t()

Adds a vertices command to the document.