CanvasCraft (canvas_craft v0.2.0)
View SourceCanvasCraft - 2D graphics drawing library facade.
This module delegates drawing operations to the Skia backend by default.
The canvas handle is represented as {backend_module, backend_ref}
.
Examples:
- In-memory WEBP export (no temp files): iex> {:ok, handle} = CanvasCraft.create_canvas(16, 16) iex> {:ok, bin} = CanvasCraft.export_webp(handle) iex> is_binary(bin) true
See guides/examples/
for runnable scripts demonstrating gradients, filters, images, and in-memory export.
Summary
Types
Backend-qualified canvas handle
Functions
Return capabilities supported by the selected backend
Clear the canvas to a given RGBA color (tuple {r,g,b,a}, 0..255). No-op for backends that don't support it yet.
Create a new canvas using the selected backend.
Draw UTF-8 text at x,y with RGBA color.
Export the canvas using backend. Defaults to PNG; if opts[:format] == :webp and the backend implements export_webp/2, that path is used.
Export PNG and write to file path (helper).
Export the raw RGBA buffer from the backend, if supported.
Export the canvas as WEBP binary using backend, no filesystem involved.
Export WEBP and write to file path (helper).
Fill a circle with a color.
Fill an axis-aligned rectangle. No-op for backends that don't support it yet; implemented later.
Fill an axis-aligned rectangle with a color.
Return a simple atom for smoke tests.
Load a TTF/OTF font from a filesystem path for the current backend (when supported).
Enable/disable antialiasing or set sample count (1,4,8).
Set current font size in points/pixels (backend-defined units).
Return true if backend supports the given feature
Write a binary returned from export_* to a file path (thin helper).
Types
Functions
Return capabilities supported by the selected backend
@spec clear(canvas_handle(), {0..255, 0..255, 0..255, 0..255}) :: :ok | {:error, term()}
Clear the canvas to a given RGBA color (tuple {r,g,b,a}, 0..255). No-op for backends that don't support it yet.
@spec create_canvas(pos_integer(), pos_integer(), keyword()) :: {:ok, canvas_handle()} | {:error, term()}
Create a new canvas using the selected backend.
Options:
- :backend - backend module (default: CanvasCraft.Backends.Skia)
- other backend-specific options
@spec draw_text( canvas_handle(), number(), number(), String.t(), {0..255, 0..255, 0..255, 0..255} ) :: :ok | {:error, term()}
Draw UTF-8 text at x,y with RGBA color.
@spec export_png( canvas_handle(), keyword() ) :: {:ok, binary()} | {:error, term()}
Export the canvas using backend. Defaults to PNG; if opts[:format] == :webp and the backend implements export_webp/2, that path is used.
@spec export_png_to_file(canvas_handle(), Path.t(), keyword()) :: :ok | {:error, term()}
Export PNG and write to file path (helper).
@spec export_raw(canvas_handle()) :: {:ok, {non_neg_integer(), non_neg_integer(), non_neg_integer(), binary()}} | {:error, term()}
Export the raw RGBA buffer from the backend, if supported.
@spec export_webp( canvas_handle(), keyword() ) :: {:ok, binary()} | {:error, term()}
Export the canvas as WEBP binary using backend, no filesystem involved.
@spec export_webp_to_file(canvas_handle(), Path.t(), keyword()) :: :ok | {:error, term()}
Export WEBP and write to file path (helper).
@spec fill_circle( canvas_handle(), number(), number(), number(), {0..255, 0..255, 0..255, 0..255} ) :: :ok | {:error, term()}
Fill a circle with a color.
@spec fill_rect(canvas_handle(), number(), number(), number(), number()) :: :ok | {:error, term()}
@spec fill_rect(canvas_handle(), number(), number(), number(), number()) :: :ok | {:error, term()}
Fill an axis-aligned rectangle. No-op for backends that don't support it yet; implemented later.
@spec fill_rect( canvas_handle(), number(), number(), number(), number(), {0..255, 0..255, 0..255, 0..255} ) :: :ok | {:error, term()}
Fill an axis-aligned rectangle with a color.
@spec hello() :: :world
Return a simple atom for smoke tests.
@spec load_font(canvas_handle(), Path.t()) :: :ok | {:error, term()}
Load a TTF/OTF font from a filesystem path for the current backend (when supported).
@spec set_antialias(canvas_handle(), boolean() | 1 | 4 | 8) :: :ok | {:error, term()}
Enable/disable antialiasing or set sample count (1,4,8).
@spec set_font_size(canvas_handle(), number()) :: :ok | {:error, term()}
Set current font size in points/pixels (backend-defined units).
Return true if backend supports the given feature
Write a binary returned from export_* to a file path (thin helper).