Output Formats
Choose PNG, JPEG, WebP, ICO, raw pixels, or SVG output and configure image quality and resolution.
Set format to choose the encoder for render(). It returns the encoded bytes.
Picking a format
import { } from "takumi-js";
const = < ="w-full h-full grid place-items-center bg-white">Hello Takumi</>;
const = await (, { : 1200, : 630, : "png" });
const = await (, { : 1200, : 630, : "jpeg", : 80 });
const = await (, { : 1200, : 630, : "webp", : 80 });| Format | Alpha | quality | lossless | Notes |
|---|---|---|---|---|
png (default) | Yes | No | No | Lossless. Use it for transparency or exact pixels. |
jpeg | No | Yes | No | Lossy. Draw an opaque background, since JPEG has no alpha channel. |
webp | Yes | Yes | Yes | Lossless unless you set quality. lossless: true wins. |
ico | Yes | No | No | Favicon file. At most 256 × 256 pixels. |
raw | Yes | No | No | Uncompressed RGBA bytes, width × height × 4. |
quality runs from 0 to 100 and defaults to 75. Formats marked No ignore it.
On the WebAssembly backend, WebP is always lossless. quality and lossless are accepted but
have no effect on WebP. quality still applies to JPEG.
Raw frames
format: "raw" skips encoding and returns the RGBA buffer. Feed it to ffmpeg or another encoder. The keyframe animation page streams raw frames into ffmpeg to make a video.
Device pixel ratio
devicePixelRatio sets how many image pixels each CSS pixel takes. width and height stay the image size in pixels. To render a 1200 × 630 design at twice the resolution, double the size and set the ratio to 2:
import { } from "takumi-js";
const = await (< ="w-full h-full text-6xl">Hello Takumi</>, {
: 2400,
: 1260,
: 2,
});The result is a 2400 × 1260 image. Every CSS length draws twice as large, so the layout matches a 1200 × 630 render at ratio 1. With width: 1200 and height: 630 at ratio 2, the image stays 1200 × 630 and the layout gets only 600 × 315 CSS pixels.
Dithering
dithering adds ordered Bayer noise to gradient fills before they drop to 8-bit color. This removes visible banding. It applies to render(), including raw output.
none(default)ordered-bayer
import { } from "takumi-js";
const = await (< ="w-full h-full bg-linear-to-r from-slate-900 to-slate-700" />, {
: 1200,
: 630,
: "ordered-bayer",
});Animated output
renderAnimation() encodes a sequence of scenes as WebP, APNG, or GIF. See Keyframe Animation.
Vector SVG
renderSvg() returns an SVG document string instead of a bitmap. It draws real <rect>, <path>, gradients, glyph outlines, and embedded images from the same layout.
import { , } from "takumi-js";
const = <>Hello Takumi</>;
const = await (, { : 1200, : 630 });
const = await (, { : 1200, : 630 }); SVG is a vector format, so the raster options do not apply: format, quality, lossless, dithering, drawDebugBorder, and devicePixelRatio.
Cancellation
Pass an AbortSignal as signal to cancel a render. Takumi checks it before work starts and again after fonts and images load. An aborted signal stops the render with the signal's reason.
import { } from "takumi-js/response";
export function (: ) {
return new (<>Hello Takumi</>, {
: 1200,
: 630,
: .,
});
}The signal also cancels image fetches that are still running.
Last updated on