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

example output with embedded font

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.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: svgfontembed-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f3c138593965ece009949c2fd5a5303602ae14185b1b39e7c18252dad3dd9f82
MD5 c35df43387db58104741c023ecd7396f
BLAKE2b-256 045aae270ba27a683ed65ea592c650a127af8736a24b09c86a2333a3cc82488c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: svgfontembed-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6bfbb1886599bac3fd1b4562da0d0f42c913249292f01456400b8c4badfc19e1
MD5 672dfe8a53b8f47a75198ec48caf6b18
BLAKE2b-256 3d384a690acfba88e85d7ba9445e6e2c443438ee0e43ca55d0117a5e51b63c83

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