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 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?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, it picks lossy encoding unless `lossless` is set.

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 scenes in place of an input, and the options above. See Animation.

Last updated on