SVG Processor
This Python script processes an SVG file by removing specified elements, embedding fonts, and exporting to multiple formats.
Features
- Remove SVG elements based on IDs specified in a JSON file
- Embed fonts from external files into the SVG as base64
- Optimize the SVG using scour
- Export to optimized SVG, PNG, JPEG, and thumbnail JPEG
Requirements
- Python 3.9+
- Libraries: lxml, cairosvg, scour
Docker Usage
Build the Docker image:
docker build -t svg-processor .
Run the container:
docker run -v /path/to/input:/input -v /path/to/output:/output svg-processor python svg_processor.py /input/input.svg /input/config.json /output
Replace /path/to/input and /path/to/output with actual paths.
JSON Configuration Format
See sample_config.json for an example.
remove: Array of element IDs to removefonts: Object mapping font-family names to font file pathssize: Override the size - useful when the size of the new image cannot be automatically calulated
Output
optimized.svg: Optimized SVG with embedded fontsoutput.png: PNG versionoutput.jpg: JPEG versionthumbnail.jpg: Thumbnail JPEG (128x128 max)
Description
Languages
Python
82.2%
Shell
14.1%
Dockerfile
3.7%