Crate icon_to_image

Crate icon_to_image 

Source
Expand description

§Icon to Image

A high-performance library for rendering Font Awesome icons to images.

This library provides fast icon rendering using the ab_glyph rasterizer with support for supersampling antialiasing, customizable colors and sizes, and output to PNG and WebP formats.

§Features

  • Embedded Font Awesome assets (no external files needed)
  • Fast glyph rasterization with ab_glyph
  • Supersampling for high-quality antialiased output
  • PNG and WebP output formats
  • Customizable icon and background colors (hex and RGB)
  • Flexible positioning with anchors and offsets
  • Separate icon and canvas sizes
  • Python bindings via PyO3

§Example (Rust)

use icon_to_image::{IconRenderer, RenderConfig, Color, ImageFormat, encode};

// Use embedded assets (recommended) - no external files needed
let renderer = IconRenderer::new()?;

// Or load from a custom path if you have different font versions:
// let renderer = IconRenderer::from_path("./assets")?;

let config = RenderConfig::new()
    .canvas_size(1024, 1024)
    .icon_size(800)
    .icon_color(Color::from_hex("#FF5733")?)
    .background_color(Color::transparent());

let (width, height, pixels) = renderer.render("heart", &config)?;
let png_data = encode(&pixels, width, height, ImageFormat::Png)?;
std::fs::write("heart.png", png_data)?;

Modules§

embedded
Embedded Font Awesome assets.

Structs§

Color
RGBA color representation with values from 0-255.
CssParser
Parser for Font Awesome CSS files.
IconMapping
Icon mapping containing the Unicode codepoint and font style.
IconRenderer
Icon font renderer that loads fonts and renders icons to images.
RenderConfig
Configuration for rendering an icon.

Enums§

FontStyle
Represents the font style/weight for an icon.
HorizontalAnchor
Horizontal anchor position for icon placement.
IconFontError
Errors that can occur during icon font rendering operations.
ImageFormat
Image output format.
VerticalAnchor
Vertical anchor position for icon placement.

Functions§

encode
Encode pixels to the specified format.
encode_png
Encode RGBA pixels to PNG format.
encode_webp
Encode RGBA pixels to WebP format.
save_to_file
Save pixels to a file with format determined by extension.

Type Aliases§

Result
Result type alias for operations that can fail with IconFontError.