render()
Render JSX, HTML, or a node tree to image bytes with render(), and every option it, renderSvg(), and ImageResponse take.
render() lays out its input and returns the encoded image. It takes JSX, an HTML string, or a node tree.
import { } from "takumi-js";
const = await (< ="w-full h-full bg-white">Hello</>, {
: 1200,
: 630,
});It resolves to a Buffer in Node.js and Bun, and to a Uint8Array elsewhere. With format: "raw" the bytes are the RGBA pixels, four per pixel, row by row.
renderSvg() takes the same input and options and resolves to an SVG document string. ImageResponse and measure() take them too.
Options
Prop
Type
Description
width?numberImage width in pixels. Omit it to size the width to the content.
height?numberImage height in pixels. Omit it to size the height to the content.
quality?numberEncoder quality from 0 to 100, for JPEG. For WebP, it picks lossy encoding unless `lossless` is set.
lossless?booleanEncodes WebP losslessly. WebP is lossless when neither `quality` nor `lossless` is set.
devicePixelRatio?numberImage pixels per CSS pixel. `width` and `height` stay the image size, so double them with a ratio of `2`.
fonts?FontLoader[] | Promise<FontLoader[]>Fonts this render draws with: URLs, bytes, or descriptors. Each file loads once per renderer.
fontFamilies?string[]The families text falls back through, in order. Defaults to every registered family in registration order.
images?ImageLoader[] | { sources, fetchCache, cache, ...fetchOptions }Pre-fetched images keyed by `src`, and limits for the images Takumi fetches.
emoji?"twemoji" | "blobmoji" | "noto" | "openmoji" | "fluent" | "fluentFlat" | "from-font"Where emoji glyphs come from. `from-font` draws them with the loaded fonts.
dithering?"none" | "ordered-bayer" | "floyd-steinberg"Dithers gradients before they quantize to 8-bit, which hides banding.
drawDebugBorder?booleanOutlines every box, for debugging layout.
jsx?FromJsxOptionsJSX conversion options, such as `{ defaultStyles: false }`.
renderer?RendererA renderer you configured yourself. Without it, every render in the process shares one.
module?InitInput | Promise<InitInput>A WebAssembly binary to render with, on any runtime. Ignored when `renderer` is set.
renderAnimation()
renderAnimation() encodes a list of scenes as an animated WebP, APNG, or GIF. It takes scenes in place of an input, and the options above. See Animation.
Last updated on