CanvasCraft

ElixirHex

In-memory 2D rendering with a Skia backend (Rustler NIF). 100% declarative Scene DSL for charts and UI-like scenes.

Install

Add to mix.exs:

{:canvas_craft, "~> 0.2.1"}

This builds a small native library (Rust). You need a Rust toolchain (rustup recommended).

Requirements

Features

Preview

KitchenSink

Quickstart (Declarative DSL)

Minimal scene:

import CanvasCraft.Scene

render width: 128, height: 128, path: "out.webp" do
  rect x: 16, y: 16, w: 96, h: 96, color: {0, 128, 255, 255}
end

Skia backend is default. To get a binary instead of a file:

import CanvasCraft.Scene
{:ok, webp} = render width: 320, height: 240 do
  circle cx: 120, cy: 120, r: 80, color: {30, 180, 90, 255}
end
File.write!("circle.webp", webp)

DSL essentials

Examples

Render KitchenSink (repo root):

mix run -e 'Code.compile_file("examples/kitchensink/lib/kitchensink.ex"); KitchenSink.render("kitchensink.webp", aa: 8)'
file kitchensink.webp

Or from the example folder:

cd examples/kitchensink
mix run -e 'Code.compile_file("lib/kitchensink.ex"); KitchenSink.render("output.webp", aa: 8)'
file output.webp

Tech details

Platforms & build

Troubleshooting

Contributing

See CONTRIBUTING.md. CI runs format, Credo, Dialyzer, tests, and non-blocking benches.

License

MIT