# `OpenFresco.Rasterizer`
[🔗](https://github.com/alexdont/open_fresco/blob/v0.2.0/lib/open_fresco/rasterizer.ex#L1)

SVG → PNG conversion, browser-free. Adopts `phoenix_kit_og`'s approach: an
embedded resvg/tiny-skia backend when available, with graceful fallbacks.

Backend preference (`which_backend/0`):

  * `:resvg_nif` — the `:resvg` Hex package's NIF (mrdotb/resvg_nif),
    precompiled via `rustler_precompiled`. Zero system-install burden in
    the common case. **Optional dependency** — add `{:resvg, "~> 0.5"}` to
    the host app to enable it; without it this module falls back to a CLI.
  * `:resvg_cli` — a `resvg` binary on PATH (`cargo install resvg`).
  * `:rsvg` — librsvg2's `rsvg-convert` (Debian/Ubuntu: `librsvg2-bin`).
  * `:magick` — ImageMagick (`magick`/`convert`); last-resort, lower quality.
  * `:none` — nothing reachable; `render/2` returns
    `{:error, :rasterizer_missing}` so the caller can fall back, never crash.

Errors are **returned, never raised**. No network is used — image inputs in
the SVG must be `data:` URLs or local file bytes (an embedded resvg won't
fetch remote `http(s)` hrefs; some CLI backends might, so prefer `data:`).

# `available?`

```elixir
@spec available?() :: boolean()
```

Whether any rasterizer backend is reachable on this host.

# `render`

```elixir
@spec render(
  iodata() | binary(),
  keyword()
) :: {:ok, binary()} | {:error, term()}
```

Rasterize SVG iodata/binary to PNG bytes.

`opts`: `:width` / `:height` (output size; defaults to the SVG's intrinsic
dimensions), `:timeout` (ms for a subprocess backend, default 5000), and
`:backend` (force a specific backend instead of auto-detecting).

# `which_backend`

```elixir
@spec which_backend() :: :resvg_nif | :resvg_cli | :rsvg | :magick | :none
```

The rasterizer backend reachable on this host (preference order above).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
