Skip to main content

Fast and high quality Font Awesome icon to image renderer

Project description

Icon to Image

A high-performance Rust library with Python bindings for rendering Font Awesome icons to images, with all the customizations you may want. This library natively includes the icons from Font Awesome 7.1.0 Free (solid, regular and brands).

Features:

  • Extremely fast icon rendering (~10ms for a 512x512 image)
  • Python bindings via PyO3
  • No Python dependencies: Pillow is optional only if using as an image object
  • Supersampling for high-quality antialiased output (2x by default)
  • PNG and WebP output formats, including transparency
  • Customizable icon and background colors (hex and RGB/RGBA)
  • Flexible icon positioning in large canvases with anchors and offsets
  • Command-line interface for both Rust and Python

Disclosure: This library was mostly coded with the assistance of Claude 4.5 Opus. However, I personally have reviewed all code to ensure it is accurate, have added numerous tests and demo examples to ensure it works as both intended and advertised, and have edited documentation and comments to provide greater signal as to how the package operates. I have given this project the same care and attention as I would give a project I have written from scratch.

Installation

Python

pip install icon-to-image
uv pip install icon-to-image

Rust

cargo install icon-to-image

Or, add to your Cargo.toml:

[dependencies]
icon-to-image = "0.1.5"

Command-Line Interface

Both the Rust binary and Python package provide a CLI for rendering icons.

Basic Usage

The list of included icons can be found on Font Awesome's Icon Grid and filtering to "Free" icons. The icon names do not use the fa prefix.

# (Python) View CLI documentation
icon-to-image --help

# (Rust) View CLI documentation
cargo run -- --help

# Render a heart icon to PNG
icon-to-image heart heart.png

# Render with custom color and size
icon-to-image star star.png --color "#FFD700" --size 256

# Render with transparent background
icon-to-image github logo.png --color "#333333" --background transparent

# Output as WebP
icon-to-image rocket rocket.webp --color "#FF6B35"

# Render with rotation (45 degrees clockwise)
icon-to-image arrow-right rotated.png --rotate 45

List and Search Icons

# List all available icons
icon-to-image list

# Search for icons matching a pattern
icon-to-image search arrow

Rust Usage

See the documentation on docs.rs.

Python Usage

See also the demo Jupyter Notebook for more interactive examples.

Basic Rendering

To use render_icon(), you will also need to have Pillow installed.

from icon_to_image import IconRenderer

renderer = IconRenderer()

# Render a heart icon with default settings (512x512, solid weight, black on white)
# render_icon() returns a PIL.Image directly
img = renderer.render_icon("heart")
img.save("heart.png")

Custom Colors

# Red heart on default white background
red_heart = renderer.render_icon(
    "heart",
    icon_color="#FF0000",
)

# Blue star on yellow background
blue_star = renderer.render_icon(
    "star",
    icon_color="#0066CC",
    background_color="#FFD700",
)

# Semitransparent gray ghost on transparent background
gray_ghost = renderer.render_icon(
    "ghost",
    icon_color=(128, 128, 128, 128),
    background_color=None,
)

Brand Icons

github = renderer.render_icon("github", icon_color="#333333")
python = renderer.render_icon("python", icon_color="#3776AB")

Custom Sizes

# Small icon with padding (128px icon on 256px canvas)
small = renderer.render_icon(
    "rocket",
    canvas_width=256,
    canvas_height=256,
    icon_size=128,
    icon_color="#FF6B35",
)

Icon Positioning

# Position icon at bottom-right with padding
badge = renderer.render_icon(
    "check",
    canvas_width=256,
    canvas_height=256,
    icon_size=48,
    horizontal_anchor="right",
    vertical_anchor="bottom",
    offset_x=-16,
    offset_y=-16,
    icon_color="#4CAF50",
    background_color="#E8F5E9",
)

Icon Rotation

# Rotate an arrow 45 degrees clockwise
rotated = renderer.render_icon(
    "arrow-right",
    rotate=45,  # Positive = clockwise
    icon_color="#E91E63",
)

# Rotate counter-clockwise
rotated_ccw = renderer.render_icon(
    "egg",
    rotate=-30,  # Negative = counter-clockwise
    icon_color="#2196F3",
)

Font Styles

Some Font Awesome icons have different styles. You can explicitly specify which style to use:

# Solid style (filled) - default for most icons
solid_heart = renderer.render_icon("heart", style="solid")

# Regular style (outlined)
regular_heart = renderer.render_icon("heart", style="regular")

render_icon() and render_icon_bytes()

render_icon() returns a PIL.Image directly. render_icon_bytes() returns raw encoded bytes (PNG or WebP) without requiring Pillow, which can be useful for tasks such as APIs.

# render_icon() returns PIL.Image (requires Pillow)
img = renderer.render_icon("heart", icon_color="#FF0000")
img.save("heart.png")  # Use PIL's save method

# render_icon_bytes() returns raw bytes (no Pillow needed)
png_data = renderer.render_icon_bytes("heart", icon_color="#FF0000")
with open("heart.png", "wb") as f:
    f.write(png_data)

# render_icon_bytes() supports output format selection
webp_data = renderer.render_icon_bytes("heart", output_format="webp")

Save Directly to File

The save_icon() method writes the image to disk directly from Rust for maximum performance.

renderer.save_icon("check-circle", "check.png", icon_color="#4CAF50")
renderer.save_icon("times-circle", "times.webp", icon_color="#F44336")

Query Available Icons

# Get total icon count
print(f"Total icons: {renderer.icon_count()}")

# List all icons
all_icons = renderer.list_icons()

# Search for specific icons
arrow_icons = [name for name in all_icons if "arrow" in name]

# Check if an icon exists
if renderer.has_icon("heart"):
    print("Heart icon is available")

Rust Usage

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

fn main() -> Result<(), icon_to_image::IconFontError> {
    // Use embedded assets
    let renderer = IconRenderer::new()?;

    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)?;

    Ok(())
}

API Reference

Python

Parameters

Applies to both render_icon() and render_icon_bytes():

Parameter Type Default Description
name str required Icon name
canvas_width int 512 Output width in pixels
canvas_height int 512 Output height in pixels
icon_size int 95% of canvas Icon size in pixels
supersample int 2 Antialiasing factor (1, 2, or 4)
icon_color str/tuple "#000000" Hex or RGB(A) tuple
background_color str/tuple/None "#FFFFFF" Hex, RGB(A), or None
horizontal_anchor str "center" "left", "center", "right"
vertical_anchor str "center" "top", "center", "bottom"
offset_x int 0 Horizontal offset in pixels
offset_y int 0 Vertical offset in pixels
rotate float 0 Rotation in degrees (+ = clockwise)
style str/None None "solid", "regular", or "brands"

Notes

  • This project is a recreation of my four year old Python project, icon-image. However, there were several issues with that project: the generations are slow, the generated icons were annoyingly aliased, and the Pillow code was a mess and prone to breaking. Therefore, I looked to Rust with Python bindings as it addressed all of the above issues: Claude 4.5 Opus handled them all easily. Normally this type of bespoke project would be kept as private personal project as I have a specific need for this workflow for a certain upcoming project, but Claude's generated code was good enough such that it wasn't a huge lift to polish it for public release.
  • Normally I would use fontdue for rendering the glyphs as it's more performant, however fontdue does not have the ability to render curves which is very important for most icons.
  • This library technically supports using provided Font Awesome files (e.g. the Pro variants) but I do not have access to Pro for testing.

License

MIT

Font Awesome CSS included per its MIT License.

Font Awesome font files included per their SIL Open Font 1.1 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

icon_to_image-0.1.5-cp314-cp314-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.14Windows x86-64

icon_to_image-0.1.5-cp314-cp314-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

icon_to_image-0.1.5-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

icon_to_image-0.1.5-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

icon_to_image-0.1.5-cp313-cp313-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

icon_to_image-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

icon_to_image-0.1.5-cp312-cp312-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.12Windows x86-64

icon_to_image-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

icon_to_image-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

icon_to_image-0.1.5-cp311-cp311-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.11Windows x86-64

icon_to_image-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

icon_to_image-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

icon_to_image-0.1.5-cp310-cp310-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.10Windows x86-64

icon_to_image-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

icon_to_image-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file icon_to_image-0.1.5-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 713047ea91d0f3999a0323cb9f31b9391b2641e61b94667d24fc04517b7e0cca
MD5 e124bcece58072cc63a7f742a69a5609
BLAKE2b-256 a6f08dfb3fb5bdfd814fef8ccf65ee7e3e7100d693f7ea031118de012778a1a8

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0890b1f79965a27b56a022818bc0ff4fef0073ff64654a65e1ce5cb3e2788ce8
MD5 27ea6b37f01ea5f432acbb77a69b547f
BLAKE2b-256 2178c71fafe4a3e21e00343853b38a420ddf81a7eb8222f82a58404996b8e2ac

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5cd147bb3ae6eda03ec2aaa5ffd839c8e02012e2a77b7490190d5d4f3a578745
MD5 cf1560ec48d6fa9682abfd48498e174e
BLAKE2b-256 060a76c1b36fad5d23959c133184f919b68e24bbdb7a43621cc5dd775e1b9f2f

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 07a31a3a09cb9be60c308afbe3116f6bde48c56a85033d84dc5be9568ebe04c2
MD5 bd8b21fbda831db6c1aa189ac0442398
BLAKE2b-256 b7ed1b1496e3986ebdc774b83a065f7d20edf6ef1e05d0b67b3584fdc4266adf

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 da602cc5c45f1c6ab9808f3e8a65a3348490af487f38e42bf90684957a04cf2a
MD5 57b88f17cb74e2f2be5660962220ac66
BLAKE2b-256 e90fdf41577e3ac3958dc6c9b5940b28f82b5ffe09d5e710513260f2cc339bc4

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c1ba2bed129ce8da3f86999b28639170592c48eca1f6bc74bf80d480b645590
MD5 4b00c917d1a6b6805557424121a6d0c3
BLAKE2b-256 2f2eb0d5dc008d2a5b4080b2974be3edbc427981653975e1b02f851e646dc831

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 14c0b84d47c8d0b71227628dcdbd225e6fd373126c388105321350dd5038912a
MD5 b2659cb66caf90316f06f36715d1f4da
BLAKE2b-256 243a88ae207fe0da434cbf225f9f8c730ba28ffaa9963f1ab01eceb32ba7bd20

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c3c36e97cdac8fffbc96aa61839811f1bd5bc54acb520104631ce0c47cf8d4b0
MD5 585d4cebeb5d14c61da2108b805d2252
BLAKE2b-256 980040f981861f80530afc9a102e60f85efc1c0dd0d9bde1ae51fc03177fcbfd

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e2945894bf0a89d0be57228b88d4ea97b35c3c419025b517d31df5e74ae103df
MD5 5b4c7ee70349b62d8fa715ae0bdf606b
BLAKE2b-256 227ff3268349d34a08a88cca77277370f33e88c66b45b6abb47912f0dc571b59

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6963d194537e90e46d531ea97e872bc0ad27d9d05bc4b2e9e83c1eeb76c31acc
MD5 8b68fd96e9670f3a17fc4ee0434789eb
BLAKE2b-256 33825856f78c62480f729664f39c622dd9e6443f413ab86fa189287db259791e

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0146e3fae5f6950d7a7a6d7ed36f6ee5d1c820b6b10e20236f7737b82c4c2ce5
MD5 1158ce080605f949a8a5af2d7ce525f5
BLAKE2b-256 ace199beb34f5816e3b26a7fd224dd38a012580c312f47c8f954f8a7c5fbc3b5

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac98ffe788f397db4f7596f1c96021544a3a6a5939ba1cf4e91bcba22e36e905
MD5 1a2e2d8bd2c95e4881256591be13c714
BLAKE2b-256 3294e7d14504cb8ab555a5f634d01ba6756fb874e4b4b6197276c656978d1853

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 fda150a4d9256bf6f65743ff9b3772d8f40f2b893a05f4f7af00ee6bd590c9ae
MD5 984f6aa04a5b4898a4df0dcdae21c5b2
BLAKE2b-256 e156a7cd5f973314b2b66fc70eb206118f408493c598fd82f61e8bd971b70c2d

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dc2ff085c06add3da3cd63e1632b71b814960395a82f4ce2b81be19ea89a45aa
MD5 ad9059f13b577cd99f1490bcd9f3035b
BLAKE2b-256 e8bff0857f77b32ca7ade6833c7878fdff78256d47d654e82f1c24825c98a134

See more details on using hashes here.

File details

Details for the file icon_to_image-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4228798876d5c7cc2d6db27e12bce6637254766759c878ac342dda9d0db8423e
MD5 3d96405c8cc763cd0a1e2c535af95a42
BLAKE2b-256 d7d0fe4a78b18071d5ed648c2b3724e937450b559f356c861905c93c3a94fe3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page