Skip to contents

Like render() with a .png / .pdf path, but returns the encoded document as a raw vector instead of writing a file. These are the in-memory entry points for a host that needs the bytes rather than a path — embedding a base64 data URI in an HTML widget, serving a plot from a web API, or writing to a connection — without a temp-file round-trip.

Usage

scene_png(scene, scale = 1, cvd = "none")

scene_pdf(scene)

Arguments

scene

A vl_scene(), or anything with an as_vellum_scene() method.

scale

Resolution multiplier (default 1). scale = 2 renders at twice the device pixels while keeping the same physical size — the retina / ggsave(scaling=) idiom. It multiplies dpi, so absolute units (mm, pt, in) cover proportionally more pixels and nothing about the layout changes; text does not get relatively bigger or smaller. Only raster output gains anything: a PDF's page size in points and an SVG's physical size are unchanged by construction.

cvd

Simulate a colour-vision deficiency: "none" (default), "protanopia" (red-blind), "deuteranopia" (green-blind, the common one that breaks red/green encodings), "tritanopia" (blue-blind), or "achromatopsia" (total, and a fair proxy for greyscale printing). The simulation is a post-pass over the finished raster using the Machado et al. (2009) matrices applied in linear light, so it turns an accessibility check into a one-line change instead of an export-and-upload round trip. Raster output only — a vector format has no pixels to transform, and render() warns if you ask for one.

Value

A raw vector: the encoded PNG or PDF document.

Details

Together with scene_svg() (a string) and scene_raster() (pixels), every output format vellum supports can now be produced without touching disk.

Backend degradation warnings (see render()) are surfaced here too, so a PDF that could not honour a pattern or mask reports it exactly as writing a file would.

Examples

s <- vl_scene(2, 2) |> draw(circle_grob(gp = vl_gpar(fill = "steelblue")))
png_bytes <- scene_png(s)
length(png_bytes)
#> [1] 3349
rawToChar(png_bytes[2:4]) # "PNG"
#> [1] "PNG"