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.4"

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.4-cp314-cp314-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.14Windows x86-64

icon_to_image-0.1.4-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.4-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

icon_to_image-0.1.4-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.4-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

icon_to_image-0.1.4-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.4-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

icon_to_image-0.1.4-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.4-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

icon_to_image-0.1.4-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.4-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.4-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 7849f16f67f32520213d7d21f1f26d32117f2d08b8377c255bbf5a91a329f41e
MD5 418d29add274642b31f2550e6d4229fc
BLAKE2b-256 9f74c4f10008d93f6fa797029aa9fda1403ec19bfbd1e1ba6f701197c7b549be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5333593e62550915a0eccfa90056de5219b12da667d4012a85afefa19d8d0ad4
MD5 df1a5252154ac10f11ad0da5774fd237
BLAKE2b-256 0c22a5157d7c76009d35c778e3f50b6ed38d91db6209264f31030690c46648b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5524a598af0413123f75770dcf8e27dc8eb1f3aecc124e9753d3c382be9899b
MD5 2bc7d4e483dcd1c331153f71b82e931e
BLAKE2b-256 8a02edbcefab00d3bfc3e69550ff6bc4e939f1576e3ea00215eb07e2a74dec7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4911bcd18da5fe74de280ab2ad0ada1764eed7e1fe4b96a1817e5a477576646e
MD5 d4bc9933912b35f7074c3a8f0ddc4382
BLAKE2b-256 81066d3f57dd28e56129873aa853a0a3c63a3d8d8e1bd88bb2f67c8f3d3c1960

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 10d134ff37fadda5a67d5587dba935034071902f7921a379af0d50859394f109
MD5 09c915f1583e8b91126f1c1a5e840b6a
BLAKE2b-256 7ad572f541eeeee5662bb6d39f070e2bfb342938840c55c869bb3badf72b0082

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0671cc6d51a89862dea961d89fa1c984c3f13470e6c45a40e2ca4e8eff388c5e
MD5 9d2b683448b77e59547f6985a47d9faa
BLAKE2b-256 dea7f83f1de189e9f00b2e72703065b75c6839635f6b7fff1c600543f601b10b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 70ae04aa7ce5d6584e0918cecda650c01b73f0c729cb37d1151fbec0497fae88
MD5 63d7c995b8ff1ba5b8cf323e4363f4df
BLAKE2b-256 4427f8e4b4b4c6b8eaca415b4b4046e54750e609944251bf0aecce5118341959

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 48efae8c02dadbb8550766df0788b171dcef09677a1a333008c3ede5d735fa55
MD5 c9b7d05618af1fa2e421364d89fc8904
BLAKE2b-256 0465991f2ef684e4bc263b1bfa587d2eb16a977528b653ad625393412fe4be02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ffe655f5947731f586d6c97e50e5ffab310ca8ec725fabcfc67634bb3c27af24
MD5 69752c9b5cdb9dd965e986b0ed251cb0
BLAKE2b-256 50d437b686c518c4f525a963431d14ef15bf58e99bfd0cbb405c09757b7fdd16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 241afbc9711bee986103f4097e1727777ff52fc1e869deecaf5b3cf0bda4cc3b
MD5 8649890d44a00e6e2f14c37d69dac69f
BLAKE2b-256 9a55b109991edc956cc1c8de8218d0c9f445709872b811624d410ed6906559ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 27cb95f852695ddcab3a00eed164b9269327ff0ea3fbcc0c03f412bdfc406a4c
MD5 17cd8aed890592043a7306e5f4307146
BLAKE2b-256 df2c162c7df11fd014b0c1abdaf4c82254431c371003006d728866a10e7bd62b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3f59b65e1a095a13d58d7352b29f46e33366c9c548050989b7e082ac4daf62d
MD5 08d438f36cd780783f88304eb6358fc7
BLAKE2b-256 aec707bc0e470d44b64d79d898abc38f2461703655950e7b1e99e48afbf0467e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 42e1e23a4110c4b26b4300f3ba2322b50afcaea089b94ae0d26744b947f5b9ea
MD5 52a36e42bba22a6221227125f03d9f0a
BLAKE2b-256 2f95e6cbad90df8a46a1caa0e3a1290bf42b890955f45e660f1b57ccb17340bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 114d48bd7f2c5547ea591ea3473e66b9ce39a0886cb4f032bebc1e21d6a3db5b
MD5 cb8cd2a83fb1da62f27ae301d57b5bbc
BLAKE2b-256 0d7c09f3bf71f23e6e2bf5efe93579f7e55d153af378601f28573450ed475005

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for icon_to_image-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 658e80fbe740d38f5da41ab0005d9a3d6da4c8058e3739037a8a674a7e9c0ecf
MD5 7b7d041f26b05a3bfffe02969f16bbd1
BLAKE2b-256 b36525ce684cfa1a77444f48ed6a520e7b063c86fcd97d42f941b4675d9ffbd7

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