GithubHelp home page GithubHelp logo

zanzi007 / svgmanip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crazypython/svgmanip

0.0 0.0 0.0 21 KB

programmatically import, manipulate, and composite together existing SVG files

License: Apache License 2.0

Python 100.00%

svgmanip's Introduction

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.

svgmanip's People

Contributors

crazypython avatar alexsavio avatar vilhelmen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.