Crates.io | takumi |
lib.rs | takumi |
version | 0.27.6 |
created_at | 2025-06-12 12:33:14.482895+00 |
updated_at | 2025-08-24 16:46:00.263663+00 |
description | Render your React components to images. |
homepage | https://takumi.kane.tw |
repository | https://github.com/kane50613/takumi |
max_upload_size | |
id | 1709737 |
size | 4,422,108 |
Takumi is a library with different parts to render your React components to images. This crate contains the core logic for layout, rendering.
Checkout the Getting Started page if you are looking for Node.js / WASM bindings.
Everything starts with a ImageRenderer
instance, it takes Node
tree as input then calculate the layout.
You can then draw the layout to an RgbaImage
.
use takumi::{
layout::{
node::{ContainerNode, TextNode, NodeKind, Node},
Viewport,
style::Style,
},
rendering::ImageRenderer,
GlobalContext,
};
// Create a node tree with `ContainerNode` and `TextNode`
let mut node = ContainerNode {
children: Some(vec![
TextNode {
text: "Hello, world!".to_string(),
style: Style::default(),
}.into(),
]),
style: Style::default(),
};
// Inherit styles for children
node.inherit_style_for_children();
// Create a context for storing resources, font caches.
// You should reuse the context to speed up the rendering.
let context = GlobalContext::default();
// Load fonts
context.font_context.load_and_store(include_bytes!("../../assets/fonts/noto-sans/google-sans-code-v11-latin-regular.woff2").to_vec());
// Create a renderer with a viewport
// You should create a new renderer for each render.
let mut renderer: ImageRenderer<NodeKind> = ImageRenderer::new(Viewport::new(1200, 630));
// Construct the taffy tree, this will calculate the layout and store the result in the renderer.
renderer.construct_taffy_tree(node.into(), &context);
// Draw the layout to an `RgbaImage`
let image = renderer.draw(&context).unwrap();