Images & emoji
Load images, cache resources, and render emoji.
External Images
By default, Takumi will fetch external images in src attributes and CSS properties like background-image and mask-image.
If you want to add additional caching layer, you can pass resourcesOptions.cache to render function.
import { } from "takumi-js";
const = < ="https://example.com/image.png" />;
const = new <string, ArrayBuffer>();
const = await (, {
: {
,
},
});Pre-fetched Images
Provide images by key so the renderer doesn't have to fetch them itself. Each key can be used in any src field or in the background-image / mask-image CSS properties.
import { } from "takumi-js/response";
export function () {
return new (< />, {
: [
{
: "my-logo",
: () => ("/logo.png").(() => .()),
},
{
: "background",
: () => ("/background.png").(() => .()),
},
],
});
}
function () {
return (
<
={{
: "url(background)",
}}
>
< ="my-logo" />
</>
);
}Decode caching
Takumi caches each decoded image so a repeated src is decoded once. The cache mode on an image controls that cache and is independent of the byte cache above: resourcesOptions.cache stores fetched bytes, while cache stores the decoded pixels.
auto(default): cache the decoded image; the entry is evictable.none: skip the cache. Use it for a one-off image you won't render again, to avoid holding its pixels in memory.
import { } from "takumi-js/response";
export function () {
return new (< />, {
: [
{
: "banner",
: () => ("/banner.png").(() => .()),
: "none",
},
],
});
}Emoji
Dynamic fetching
ImageResponse accepts a satori-compatible emoji option.
import { } from "takumi-js/response";
export function () {
return new (< ="flex justify-center items-center text-3xl">Hello 👋😁</>, {
: "twemoji",
});
}It calls the extractEmojis helper. The helper splits emoji from text and turns them into <img> nodes on a CDN. Run the steps yourself when you need the resources separately.
import { } from "takumi-js/helpers/emoji";
import { } from "takumi-js/helpers/jsx";
import { , } from "takumi-js/helpers";
import { } from "takumi-js/node";
let { } = await (< ="flex justify-center items-center text-3xl">Hello 👋😁</>);
= (, "twemoji");
const = ();
const = await ();
const = new ();
const = await .(, {
,
});extractEmojis also takes blobmoji, noto, openmoji, fluent, and fluentFlat.
COLR / bitmap fonts
Takumi renders COLR fonts, the format behind packs like Twemoji-COLR. A COLR file is much smaller than a bitmap emoji font like Noto Color Emoji. Register one through fonts and set emoji: "from-font". The renderer then draws emoji from the loaded glyphs instead of fetching images, with no network request.
Last updated on