#png #font-rendering #font #text-image #svg #rendering #text

text-to-png

A simple way to render text to a png image with basic options

3 unstable releases

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

#455 in Visualization

Download history 25/week @ 2023-12-10 58/week @ 2023-12-17 108/week @ 2023-12-24 78/week @ 2023-12-31 79/week @ 2024-01-07 100/week @ 2024-01-14 85/week @ 2024-01-21 136/week @ 2024-01-28 544/week @ 2024-02-04 229/week @ 2024-02-11 581/week @ 2024-02-18 373/week @ 2024-02-25 356/week @ 2024-03-03 404/week @ 2024-03-10 356/week @ 2024-03-17 84/week @ 2024-03-24

1,209 downloads per month
Used in 3 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

~8.5MB
~165K SLoC