takumi

Crates.iotakumi
lib.rstakumi
version0.65.0
created_at2025-06-12 12:33:14.482895+00
updated_at2026-01-21 14:15:39.942492+00
descriptionRender your React components to images.
homepagehttps://takumi.kane.tw
repositoryhttps://github.com/kane50613/takumi
max_upload_size
id1709737
size14,740,442
Kane Wang (kane50613)

documentation

README

Takumi

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 Quick Start if you are looking for napi-rs / WASM bindings.

Example

use takumi::{
  layout::{
    node::{ContainerNode, TextNode, NodeKind, Node},
    Viewport,
    style::Style,
  },
  rendering::{render, RenderOptionsBuilder},
  GlobalContext,
};

// Create a node tree with `ContainerNode` and `TextNode`
let mut node = NodeKind::Container(ContainerNode {
  children: Some(Box::from([
    NodeKind::Text(TextNode {
      text: "Hello, world!".to_string(),
      style: None, // Construct with `StyleBuilder`
      tw: None, // Tailwind properties
      preset: None,
    }),
  ])),
  preset: None,
  style: None,
  tw: None, // Tailwind properties
});

// Create a context for storing resources, font caches.
// You should reuse the context to speed up the rendering.
let mut global = GlobalContext::default();

// Load fonts
global.font_context.load_and_store(include_bytes!("../../assets/fonts/geist/Geist[wght].woff2"), None, None);

// Create a viewport
let viewport = Viewport::new(Some(1200), Some(630));

// Create render options
let options = RenderOptionsBuilder::default()
  .viewport(viewport)
  .node(node)
  .global(&global)
  .build()
  .unwrap();

// Render the layout to an `RgbaImage`
let image = render(options).unwrap();

Feature Flags

  • woff2: Enable WOFF2 font support.
  • woff: Enable WOFF font support.
  • svg: Enable SVG support.
  • rayon: Enable rayon support.

Credits

Takumi wouldn't be possible without the following works:

  • taffy for the flex & grid layout.
  • image for the image processing.
  • parley for text layout.
  • swash for font shaping.
  • wuff for woff/woff2 decompression.
  • resvg for SVG parsing & rasterization.
Commit count: 1607

cargo fmt