Skip to main content

svgmanip

Say Thanks!

svgmanip is a library that helps import and composite together existing SVG files. It supports a superset of the features supported by svgutils. For example, you can easily rotate and scale SVGs on the fly. In Warfrogs, this code:

from svgmanip import Element
output = Element(384, 356)  # size of the output file.

fate = Element('assets/fate.svg').rotate(-15)
skip = Element('assets/skip.svg').rotate(-5)
attack = Element('assets/attack.svg').rotate(5)
output.placeat(fate, 0.73, 23.55)
output.placeat(skip, 107.81, 8.76)
output.placeat(attack, 170.9, 0.08)

output.dump('output.svg')
output.save_as_png('output.png', 1024)

Generates this image:

(The cropped edges are because of the output dimensions, which are customizable.)

Unlike svgutils (which this module is based on), .rotate() rotates about the center of the graphic, instead of the top left corner. This produces results the user would expect.

Did you notice that you didn’t need to specify the dimensions of an imported image? That’s because svgmanip detects it automatically behind the scenes!

.dumps() grabs the full, real SVG code, not just the root element like .tostr() in svgutils.

Install

npm install -g svgexport  # if you want to be able to export to PNG
pip install svgmanip

Documentation

.rotate() additionally supports passing optional x and y coordinates.

Since the Element class inherits from the Figure class in svgutils, it also supports these svgutils methods:

  • .scale(factor) - scale the SVG by a particular factor

  • .find_id(element_id) - find the inner SVG element with the given id. This method is guranteed to return an Element object fromsvgmanip.

  • .find_ids(element_ids) - find the inner SVG elements with the given ids. This returns a Panel object from svgutils.

svgmanip also supports these methods in addition to the ones listed in the example:

  • .dumps - dump to a string

  • .loads - load from a string

  • .load - load from a file (note: using the default constructor is reccomended in this context)

  • .to_png - returns the generated PNG as a string

License

Apache 2.0. Example image of the Warfrogs cards is licensed under the CC BY-NC-ND 4.0.

Release files for svgmanip 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svgmanip 0.0.12
File Size Uploaded
svgmanip-0.0.12.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for svgmanip 0.0.12
File Interpreter ABI Platform
svgmanip-0.0.12-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 18.4 kB

Release files / svgmanip-0.0.12.tar.gz

Download URL svgmanip-0.0.12.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
de18505b198debd4b031707160831b5ffd72077c1fc242a2d554fb8eabfa71ca
BLAKE2b-256 checksum
How to use checksums
db53e0000a361a170b8b43ec0f14bd3e3a65e5e1bc1d1a6b1791bf314449dff1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / svgmanip-0.0.12-py2.py3-none-any.whl

Download URL svgmanip-0.0.12-py2.py3-none-any.whl
Size 9.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a3aafe8abc94796661095ec3eac632cac348d03bf2c33f480d1b6377117b1c66
BLAKE2b-256 checksum
How to use checksums
6da7071c99116e3dd80f06062be60a566b8ff223e21298766b6d071212168d48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.10

2 release files

0.0.8

2 release files

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page