2026-03-30 22:14:29 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 22:14:29 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 22:14:29 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 00:26:18 +00:00
2026-03-30 00:26:18 +00:00

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 remove
  • fonts: Object mapping font-family names to font file paths
  • size: Override the size - useful when the size of the new image cannot be automatically calulated

Output

  • optimized.svg: Optimized SVG with embedded fonts
  • output.png: PNG version
  • output.jpg: JPEG version
  • thumbnail.jpg: Thumbnail JPEG (128x128 max)
Description
No description provided
Readme 93 KiB
Languages
Python 82.2%
Shell 14.1%
Dockerfile 3.7%