svg2many (C) Alexander Iurovetski 2025-2026
Convert an SVG file to raster images of multiple sizes, optionally splitting into background and foreground images
This application produces all raster images you need (.png, .webp, or others) from a single .svg file. Since the SVG format is text (XML), there is a rational way to manipulate width, height, scale, offset and visibility of layers.
Dependencies:
- envara: a package for the comprehensive environment variable expansion on various platforms
- resvg-py: a safe and high-level binding for the resvg project that is used to convert an
.svgto a.png(you can still use any external application of your choice instead) - pillow: the current implementation of The Python Imaging Library, used to convert between various raster image formats
Usage
This example can be used to generate all launcher icons for a Flutter project. See also JSON Configuration File Format below.
-
Install
svg2manyfrom PyPI. -
Create your SVG image. Avoid percentages for coordinates or sizes — those are scaled inconsistently. A 100x100 pixel image is a good base:
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"> <g class="background"> <!-- actual background --> </g> <g class="foreground"> <!-- actual foreground --> </g> </svg>
Do not use
transformordisplayattributes/styles on these<g>elements — they will be overwritten at export time. See the repo's examples. -
Create a JSON configuration file (or adapt one from the examples).
-
Create
envfile(s) if needed. -
Ensure
svg2manyis onPATH. -
Run:
svg2many [OPTIONS] [ARGUMENTS]
Command-line options
-h, --help
: Help screen.
-D, --demo DEMO
: Run a demo for: Android, Flutter (default), iOS, Linux, macOS, Web,
Windows (case-insensitive). Creates ~/Projects/my_app with output
images. Android demo requires cwebp.
-c, --config CONFIG
: JSON configuration — a file path, comma-separated glob patterns, or
inline JSON (surrounded by {}). Default: read from stdin.
-d, --delete
: Delete generated files (directories are kept).
-e, --env DIR
: Directory with .env files. Files are loaded in order: .env,
then platform-specific ones (posix.env, windows.env, etc.),
then svg2many.env. Lines follow name = value format. The
first non-empty leading character selects the expansion rules
(# = POSIX, :: = Windows, ! = OpenVMS).
-q, --quiet
: Suppress all output. Mutually exclusive with -v.
-v, --verbose
: Detailed logging for troubleshooting. Mutually exclusive with -q.
ARGUMENTS
: Extra positional arguments referenced as $1, $2 (POSIX) or
%1, %2 (Windows) inside the config. E.g. a project name used
in output paths.
How conversion works
The SVG is modified (scaled, layer-visibility applied) and then fed to an
external command defined by the export or after config keys. The
command receives the SVG via stdin (or a temp file when {i} is
present). You can use any rasterizer:
{resvg}(built-in, recommended) — usesresvg-pyfor fast, high-quality conversion. Supports an extra-T/--out-typeoption to further convert from the initialPNGto any Pillow-supported format.rsvg-convert— works well on Linux; Windows support is limited.magick(ImageMagick), Inkscape, headless Chrome.
Inline examples
# Linux / macOS / PowerShell
svg2many -c '{"export":"{resvg} {i} {o}","inpFile":"...","targets":[{"outDir":"...","output":[{"size":"64","file":"{n}.png"}]}]}'
REM Windows cmd (caret escaping)
svg2many -c "{^"export^":^"{resvg} {i} {o}^",^"inpFile^":^"...^",^"targets^":[{^"outDir^":^"...^",^"output^":[{^"size^":^"64^",^"file^":^"{n}.png^"}]}]}"
For PowerShell use ` (backtick) as the escape character instead of
^.
JSON Configuration File Format
Root-level nodes
$.rootDir
: Top directory for input/output files. Defaults to the config file's
directory (or cwd if config is read from stdin).
$.inpFile
: Input SVG file path. Read from stdin when null, empty, or
"-".
$.export
: Command to export an SVG to a raster image. Overridden by
$.targets.target.export.
$.after
: Post-export command (e.g. {png2ico}). Overridden by
$.targets.target.after.
$.bkgClass
: CSS class for the background layer (default: "background").
$.frgClass
: CSS class for the foreground layer (default: "foreground").
$.outType
: Output file type without leading dot (e.g. png, webp).
$.targets
: Array of per-image rule sets (see below).
Target-level nodes ($.targets[n])
$.targets.target.title
: Log label.
$.targets.target.check
: Glob pattern(s) for incremental-build timestamp checks.
Examples: {O}/*.ico, {O}/{n}.ico.
$.targets.target.delete
: If true, delete all files listed under this target after
conversion.
$.targets.target.outDir
: Output sub-directory (relative to rootDir) or absolute path.
$.targets.target.output
: Array of output size/filename entries. Each entry has:
size: Dimensions asWxHor a single number (square). An optional foreground size follows after a space.file: Output filename (sub-path relative tooutDir).
$.targets.target.export
: Overrides $.export for this target.
$.targets.target.after
: Overrides $.after for this target.
$.targets.target.bkgClass
: Overrides $.bkgClass for this target.
$.targets.target.frgClass
: Overrides $.frgClass for this target.
$.targets.target.outType
: Overrides $.outType for this target.
Built-in Commands
Commands prefixed with {...} resolve to internal methods:
{resvg}
: The default SVG-to-PNG converter using resvg-py. Supports
-T / --out-type to output any Pillow format.
{png2gif}
: Convert one or more PNGs into a single GIF (animated if multiple
inputs).
-c TEXT — add a comment
-d N — disposal (0=none, 1=keep, 2=restore bg, 3=restore prev)
-f N — frames per second (0–25, default 12)
-l N — loop count (0 = forever)
-o — optimize palette (default)
-t N — transparency colour index
{png2ico}
: Convert one or more PNGs into a single ICO.
-b — save as uncompressed bitmaps
{png2jpg}
: Convert a PNG into a JPEG.
-c TEXT — add a comment
-k — keep RGB (don't convert to YCbCr)
-o — optimize Huffman tables (slower, smaller)
-p — progressive JPEG
-q N — quality 0–100 (default 75)
-s N — smoothing factor (0 = off)
{png2pdf}
: Convert one or more PNGs into a PDF (animated if multiple inputs).
-A TEXT — document author
-C TEXT — creator name
-c TEXT — creation date/time
-d N — DPI resolution (default 72)
-k TEXT — keywords
-l TEXT — document language (PDF 2.0)
-m TEXT — modification date/time
-O — disable deflate compression (default: on)
-p W,H or WxH or — page size (e.g. 8.5x11; default: image size in pt)
-P TEXT — producer name
-S TEXT — subject
-T TEXT — document title
{png2webp}
: Convert one or more PNGs into a single WebP.
-a N — alpha quality 0–100
-e — preserve transparent RGB values
-l — lossless compression
-m N — method 0 (fast) to 6 (slow/best)
-q N — quality 0–100 (default 80)
Use - in place of any filename to indicate stdin or stdout.
Built-ins can be chained with pipes: the command must start with a built-in, and all built-ins must be connected by pipes. A single external app may follow the last built-in.
Placeholders
Do not wrap placeholders in quotes (even when paths may contain spaces — the framework handles escaping).
{i}
: Input SVG file path. If absent from the command, the SVG content is
fed via stdin; otherwise written to a temp file.
{n}
: Input filename without extension(s).
{o}
: Current output file path.
{t}
: Current output file type (from outType).
{w}
: Output image width (largest of background/foreground).
{h}
: Output image height (largest of background/foreground).
{I}
: Input directory path.
{O}
: Output directory path.
Extra Expansions
References to the environment variables will be expanded:
- Portable:
$ABC,${ABC:-$DEF}. - Windows:
%ABC%.
References to the arguments passed to the script will also be expanded:
- Portable:
$1,${2:-abc}. - Windows:
%1,%2.
Good Luck!
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file svg2many-1.0.1.tar.gz.
File metadata
- Download URL: svg2many-1.0.1.tar.gz
- Upload date:
- Size: 49.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e463dd115ed2b3db8491ba9c04ce3aa2062667d9d96bd11f25eb8df72a0c7c8
|
|
| MD5 |
cf283c398a2b6861ba5196fdbe86fc91
|
|
| BLAKE2b-256 |
16d9211003ce5add9db196e133c64363854205a6d4fa5e4c3a0a530f4f4f3370
|
File details
Details for the file svg2many-1.0.1-py3-none-any.whl.
File metadata
- Download URL: svg2many-1.0.1-py3-none-any.whl
- Upload date:
- Size: 60.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b00af30e2cda1b30b71aa1ce42e033da590ed2ae74cb0593215bc1e3427bef3
|
|
| MD5 |
c43225b7c2a5fe07d86d69ceeaded9cd
|
|
| BLAKE2b-256 |
f6e07cb1f02cba21b779463f91b33576fa5151a219c9a959950f3da0f3606faf
|