Skip to main content

No project description provided

Project description

svgfontembed

svgfontembed is a Python CLI tool that allows you to embed fonts in SVG files, ensuring that the text in your images is displayed correctly even without internet access or if the linked font is no longer available. This is also good for privacy, as font downloads can be used for tracking purposes.

How it works

svgfontembed takes an SVG file as input and replaces any fonts that are fetched via a link with an embedded font, stripped down to only the subset of characters used within the text in the SVG. It does this by downloading the linked font and generating a base64 WOFF2 string, which is then used to replace the link in the SVG file. If an unused font is included and the --keep-unused option is not used, it is removed altogether.

The benefit of this is that the resulting SVG file will be self-contained and can be opened and displayed correctly on any device, even if the original font is no longer available. Additionally, the embedded font will only contain the characters that are actually used in the SVG, resulting in a smaller overall file size.

It's worth noting that the embedded font will not be cached by the browser, so if many SVG files use the same font, it may be more economical to just have the browser download the original font (though it will no longer be available offline).

Reminder: Please be sure to observe the license of any fonts you use with this tool.

Installation

svgfontembed is available on PyPI. The recommended install method is to use pipx:

pipx install svgfontembed

It can can be installed with pip:

pip install svgfontembed

Usage

To use svgfontembed, simply install it using pip and run the following command:

svgfontembed INPUT_SVG [OUTPUT_SVG] [--inplace] [--overwrite] [--keep-unused]

This will process the input SVG file and save the resulting file with embedded fonts to the specified output file. If --inplace is used, the input file will be overwritten with the output. If --overwrite is used, any existing files will be overwritten. If --keep-unused is used, fonts that are not used in the SVG will not be removed.

Examples

Here are some examples of how you might use svgfontembed:

# Process input.svg and save to output.svg
svgfontembed input.svg output.svg

# Process input.svg and save to the current working directory
svgfontembed input.svg

# Process input.svg and overwrite it with the output
svgfontembed input.svg --inplace

# Process input.svg and save to output.svg, overwriting any existing files
svgfontembed input.svg output.svg --overwrite

# Process input.svg and save to output.svg, keeping unused fonts in the output
svgfontembed input.svg output.svg --keep-unused

License

svgfontembed is licensed under the MIT license. See the LICENSE file for more details.

To-Do

  • Clean up code and dependencies
  • Test on more files (currently only files output from Excalidrawn have been tested)
  • Load fonts which are already present as embedded base64 and strip unused characters

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

svgfontembed-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

svgfontembed-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file svgfontembed-0.1.0.tar.gz.

File metadata

  • Download URL: svgfontembed-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/6.1.0

File hashes

Hashes for svgfontembed-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc22d28ec8889d1d2b9dc968b8be96e1c1e2ae5196e561091282a0d7c640abf9
MD5 d104ac3dc6b0b4e349800d72d715afe3
BLAKE2b-256 ff75aaee275a6e963575123cd36be418681d6525dd58bd86cc938044ed272338

See more details on using hashes here.

File details

Details for the file svgfontembed-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: svgfontembed-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/6.1.0

File hashes

Hashes for svgfontembed-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53d933cb96ed44a492a414048ed3c4f6f0ca144b621719dd8ac4c4efea5c1491
MD5 5b922e98fbfdb6264fb526b51f357c87
BLAKE2b-256 7840c8d34627e9b5e17aa312901a3c68ac11bd04bd28997675adb544505e5516

See more details on using hashes here.

Supported by

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