Takumi

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.

Render a PNG
import {  } from "takumi-js";

const  = await (< ="w-full h-full bg-white">Hello</>, {
  : 1200,
  : 630,
});

It resolves to a Buffer on the native backend, which Node.js and Bun use unless you pass module, and to a Uint8Array on WebAssembly. With format: "raw" the bytes are the RGBA pixels, four per pixel, row by row.

renderSvg() takes the same input and options, except the raster-only format, quality, lossless, dithering, drawDebugBorder, and devicePixelRatio, and resolves to an SVG document string. ImageResponse and measure() take them too.

Options

Prop

Type

Description

width?number

Image width in pixels. Omit it to size the width to the content.

height?number

Image height in pixels. Omit it to size the height to the content.

format?"png" | "jpeg" | "webp" | "ico" | "raw"

The encoder. `raw` returns the RGBA pixels unencoded.

quality?number

Encoder quality from 0 to 100, for JPEG. For WebP on the native backend, it picks lossy encoding unless `lossless` is set. WebAssembly always encodes WebP losslessly and ignores it.

lossless?boolean

Encodes WebP losslessly. WebP is lossless when neither `quality` nor `lossless` is set.

devicePixelRatio?number

Image 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.

lang?string

The BCP-47 language of the root, which nodes without their own `lang` inherit.

css?CssInput | CssInput[]

Stylesheet text or rule objects, cascading in 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.

timeMs?number

The point on the animation timeline to render, in milliseconds.

dithering?"none" | "ordered-bayer" | "floyd-steinberg"

Dithers gradients before they quantize to 8-bit, which hides banding.

drawDebugBorder?boolean

Outlines every box, for debugging layout.

jsx?FromJsxOptions

JSX conversion options, such as `{ defaultStyles: false }`.

signal?AbortSignal

Cancels the render while it loads fonts and images.

renderer?Renderer

A 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 one options object that holds scenes and requires width, height, and fps, and its format is "webp", "apng", or "gif" rather than the static formats above. See Animation.

Last updated on