Skip to main content

Crate takumi

Crate takumi 

Source
Expand description

Takumi renders a UI component tree to an image.

This crate is the facade. The entry-point functions live at the crate root; the curated, stable types live in prelude. Glob the prelude, build a node tree, and call render.

§Example

use takumi::prelude::*;
use takumi::render;

let node = Node::container([Node::text("Hello, world!").with_style(
  Style::default().with(StyleDeclaration::font_size(Length::Px(32.0).into())),
)]);

// Reuse one font context across renders to share the decode cache.
let mut fonts = Fonts::default();
fonts.register(FontResource::new(include_bytes!(
  "../../assets/fonts/geist/Geist[wght].woff2"
)))?;

let options = RenderOptions::builder()
  .viewport(Viewport::new((1200, 630)))
  .node(node)
  .fonts(&fonts)
  .build();

let image = render(options)?;

§Feature flags

  • raster-backend (default): raster rendering backend.
  • svg-source (default): SVG image sources in the core and raster backend.
  • svg-backend: vector SVG output backend (render_svg).
  • woff2: WOFF2 font support.
  • woff: WOFF font support.
  • rayon: parallelism in the raster backend; needs raster-backend.
  • unstable: re-export the backend crates with no semver guarantee.

Modules§

prelude
The curated, stable data structures for building a node tree and configuring a render.
unstable
Unstable, semver-exempt access to the backend crates in full.

Functions§

from_html
Parse HTML markup into a node tree.
measure
Measures the layout of a node.
render
Renders a node to an image.
render_animation
Renders all frames for a sequential animation timeline at a fixed frame rate.
render_svg
Renders a node tree to a vector SVG string.
write_animated_gif
Encode a sequence of RGBA frames into an animated GIF and write to destination.
write_animated_png
Encode a sequence of RGBA frames into an animated PNG and write to destination.
write_animated_webp
Encodes a sequence of RGBA frames into an animated WebP.
write_animation
Renders a timeline at fps and streams each frame straight into format, holding one raw frame at a time instead of the whole animation.
write_image
Writes a single rendered image to destination using format.