OpenFresco.Rasterizer (open_fresco v0.1.0)

Copy Markdown View Source

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:).

Summary

Functions

Whether any rasterizer backend is reachable on this host.

Rasterize SVG iodata/binary to PNG bytes.

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

Functions

available?()

@spec available?() :: boolean()

Whether any rasterizer backend is reachable on this host.

render(svg, opts \\ [])

@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()

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

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