Skip to main content

Convert Font Awesome HTML tags into inline SVG

Project description

fa2svg

A small Python package that converts Font Awesome <i>/<span> tags into email‑friendly inline images. You can embed either raw SVG (to_inline_svg) or high‑density PNG (to_inline_png_img), preserving font‑size, color, aspect ratio, and baseline alignment. Includes a simple test script at tests/run_test.py to verify basic functionality.


Installation

pip install fa2svg

Or for local development:

git clone https://github.com/meena-erian/fa2svg.git
cd fa2svg
pip install -e .

Upload to PyPI

Ensure your .pypirc is configured, then:

# from project root
env/bin/python -m build
twine upload --config-file "./.pypirc" dist/*

Usage

from fa2svg.converter import to_inline_svg, to_inline_png_img

html = '''
  <p>
    Coffee time:
    <i class="fas fa-mug-saucer" style="font-size:64px;color:#c60"></i>
    and stars:
    <span class="far fa-star" style="font-size:48px;color:gold"></span>
  </p>
'''

# Embed as SVG data URI:
converted_svg = to_inline_svg(html)

# Embed as higher-resolution PNG data URI:
converted_png = to_inline_png_img(html)

print(converted_svg)
print(converted_png)

API

  • to_inline_svg(html: str) -> str

    Fetches the correct FA SVG, inlines your font-size and color, and outputs an <img> tag with a base64‑encoded SVG data URI, plus width, height, and vertical-align CSS.

  • to_inline_png_img(html: str) -> str

    Same as above but renders a PNG at higher pixel density (default 2×) for crisper images in clients with varying DPI.


Testing

A basic test harness is provided at tests/run_test.py:

python -m tests.run_test

Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Commit & push your changes
  4. Open a Pull Request

Issues and PRs are very welcome!

Project details


Download files

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

Source Distribution

fa2svg-0.1.6.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

fa2svg-0.1.6-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file fa2svg-0.1.6.tar.gz.

File metadata

  • Download URL: fa2svg-0.1.6.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for fa2svg-0.1.6.tar.gz
Algorithm Hash digest
SHA256 23188497a889510cc2fb0f5e302a7dfb110aa3f152821af4b85f3c769c619f04
MD5 bb5995f4a1d2cf583b617f063b01550f
BLAKE2b-256 db8d6b3b03d665801e8a6f6193e5b8a821d0af60ab7fdd05c82d46e49e3080ac

See more details on using hashes here.

File details

Details for the file fa2svg-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: fa2svg-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for fa2svg-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bb9a74b87ccc7c03d3e1bb28a88b48c6f9919072986c77c835a3a75a748d105e
MD5 17387aea92ebb2caf3e4bfe73e67f004
BLAKE2b-256 c38a2389fa6a0db9d5d66e26b23b97297f0512f9af59730f57669cc5b7e2ba36

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