OpenFresco.Renderer (open_fresco v0.1.0)

Copy Markdown View Source

The PNG facade: scene → SVG → raster → PNG bytes. Browser-free and deterministic.

render/3 never raises — every failure (a missing rasterizer, a crafted scene, a subprocess timeout) is an {:error, term}. It performs no network I/O; image inputs in the scene must be data: URLs or local files (see OpenFresco.Rasterizer).

The heavy work lives in the optional :resvg dependency; hosts that only use the SVG generator (OpenFresco.render_svg/3) or the editor don't pay for it. Without a reachable backend, render/3 returns {:error, :rasterizer_missing} so the caller can fall back to its own image rather than crash.

Summary

Functions

Whether a rasterizer backend is reachable (else render/3 errors out).

Render a scene to PNG bytes.

A version string for cache keys — folds the SVG generator version and the rasterization revision, so cached PNGs invalidate when either changes.

Functions

available?()

@spec available?() :: boolean()

Whether a rasterizer backend is reachable (else render/3 errors out).

render(scene, values \\ %{}, opts \\ [])

@spec render(OpenFresco.Scene.t(), map(), keyword()) ::
  {:ok, binary(), %{width: pos_integer(), height: pos_integer()}}
  | {:error, term()}

Render a scene to PNG bytes.

Returns {:ok, png_binary, %{width: w, height: h}} (dimensions are the clamped canvas size, for og:image:width/height hints) or {:error, term}.

values / opts are as OpenFresco.render_svg/3 (:globals, :max_dimension), plus:

  • :timeout — subprocess-backend wallclock ms (default 5000).
  • :backend — force a rasterizer backend instead of auto-detecting.

version()

@spec version() :: String.t()

A version string for cache keys — folds the SVG generator version and the rasterization revision, so cached PNGs invalidate when either changes.