Skip to main content

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 .svg to 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.

  1. Install svg2many from PyPI.

  2. 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 transform or display attributes/styles on these <g> elements — they will be overwritten at export time. See the repo's examples.

  3. Create a JSON configuration file (or adapt one from the examples).

  4. Create env file(s) if needed.

  5. Ensure svg2many is on PATH.

  6. 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) — uses resvg-py for fast, high-quality conversion. Supports an extra -T / --out-type option to further convert from the initial PNG to 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 as WxH or a single number (square). An optional foreground size follows after a space.
  • file: Output filename (sub-path relative to outDir).

$.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

svg2many-1.0.1.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

svg2many-1.0.1-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

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

Hashes for svg2many-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9e463dd115ed2b3db8491ba9c04ce3aa2062667d9d96bd11f25eb8df72a0c7c8
MD5 cf283c398a2b6861ba5196fdbe86fc91
BLAKE2b-256 16d9211003ce5add9db196e133c64363854205a6d4fa5e4c3a0a530f4f4f3370

See more details on using hashes here.

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

Hashes for svg2many-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b00af30e2cda1b30b71aa1ce42e033da590ed2ae74cb0593215bc1e3427bef3
MD5 c43225b7c2a5fe07d86d69ceeaded9cd
BLAKE2b-256 f6e07cb1f02cba21b779463f91b33576fa5151a219c9a959950f3da0f3606faf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page