| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
npm install -g svgexport # if you want to be able to export to PNG pip install svgmanip
.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:
svgmanip also supports these methods in addition to the ones listed in the example:
Apache 2.0. Example image of the Warfrogs cards is licensed under the CC BY-NC-ND 4.0.
| Back | FazBrowse Home | New Git URL |