3 unstable releases

0.2.0 Mar 5, 2022
0.1.1 Nov 8, 2021
0.1.0 Oct 25, 2021

#405 in Visualization

Download history 122/week @ 2024-07-21 583/week @ 2024-07-28 370/week @ 2024-08-04 422/week @ 2024-08-11 239/week @ 2024-08-18 114/week @ 2024-08-25 311/week @ 2024-09-01 254/week @ 2024-09-08 257/week @ 2024-09-15 443/week @ 2024-09-22 583/week @ 2024-09-29 306/week @ 2024-10-06 135/week @ 2024-10-13 394/week @ 2024-10-20 383/week @ 2024-10-27 380/week @ 2024-11-03

1,346 downloads per month
Used in 5 crates

MIT/Apache

285KB
1.5K SLoC

Text To Png

This crate provides a really simple interface for rendering basic text to a png image.

Features

  • 100% Rust! We use usvg for path vectoring, resvg for rasterizing, and tiny-skia for png conversion
  • Built-in, monospace font courtesy of Ryoichi Tsunekawa
  • Flexible color specification, "Aquamarine", "#4506AE", "EEE", 0
  • Text baseline height is provided for alignment consistency
  • Accepts true-type font files or true-type font collection files

Example

Default Font

use text_to_png::TextRenderer;

let renderer = TextRenderer::default();

let text_png = renderer.render_text_to_png_data(
    "Rénder this, brö",
    64,
    "Dark Turquoise");

Writing the &[u8] data returned in text_png.data to a text.png yields:

Rendered Text Image

Custom Font

use text_to_png::TextRenderer;

let renderer = TextRenderer::try_new_with_ttf_font_data(include_bytes!("../tests/resources/Because I am Happy Regular.ttf"))
    .expect("Example font is definitely loadable");

let text_png = renderer.render_text_to_png_data(
    "Custom Fonts are Cool!",
    52,
    0x439EC2);

Writing the &[u8] data returned in text_png.data to a text.png yields:

Rendered Text Image

CLI

See the CLI Readme

Dependencies

~9.5MB
~191K SLoC