Skip to main content

icon_to_image/
lib.rs

1//! # Icon to Image
2//!
3//! A high-performance library for rendering Font Awesome icons to images.
4//!
5//! This library provides fast icon rendering using the `ab_glyph` rasterizer
6//! with support for supersampling antialiasing, customizable colors and sizes,
7//! and output to PNG and WebP formats.
8//!
9//! ## Features
10//!
11//! - Embedded Font Awesome assets (no external files needed)
12//! - Fast glyph rasterization with `ab_glyph`
13//! - Supersampling for high-quality antialiased output
14//! - PNG and WebP output formats
15//! - Customizable icon and background colors (hex and RGB)
16//! - Flexible positioning with anchors and offsets
17//! - Separate icon and canvas sizes
18//! - Python bindings via PyO3
19//!
20//! ## Example (Rust)
21//!
22//! ```no_run
23//! use icon_to_image::{IconRenderer, RenderConfig, Color, ImageFormat, encode};
24//!
25//! // Use embedded assets (recommended) - no external files needed
26//! let renderer = IconRenderer::new()?;
27//!
28//! // Or load from a custom path if you have different font versions:
29//! // let renderer = IconRenderer::from_path("./assets")?;
30//!
31//! let config = RenderConfig::new()
32//!     .canvas_size(1024, 1024)
33//!     .icon_size(800)
34//!     .icon_color(Color::from_hex("#FF5733")?)
35//!     .background_color(Color::transparent());
36//!
37//! let (width, height, pixels) = renderer.render("heart", &config)?;
38//! let png_data = encode(&pixels, width, height, ImageFormat::Png)?;
39//! std::fs::write("heart.png", png_data)?;
40//! # Ok::<(), icon_to_image::IconFontError>(())
41//! ```
42
43mod color;
44mod css_parser;
45pub mod embedded;
46mod encoder;
47mod error;
48mod renderer;
49
50// Re-export public API
51pub use color::Color;
52pub use css_parser::{CssParser, FontStyle, IconMapping};
53pub use encoder::{
54    encode, encode_png, encode_png_with_compression, encode_webp, save_to_file, ImageFormat,
55    PngCompression,
56};
57pub use error::{IconFontError, Result};
58pub use renderer::{HorizontalAnchor, IconRenderer, RenderConfig, VerticalAnchor};
59
60// Python bindings module (only compiled when the "python" feature is enabled)
61#[cfg(feature = "python")]
62mod python;
63
64#[cfg(feature = "python")]
65pub use python::*;