Skip to content
Cythonic wrapper around nanosvg for rasterizing SVGs
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
nanosvg @ 25241c5 Update nanosvg Apr 23, 2019
svg-stubs Update stub package Jun 7, 2018
svg Add __init__.c Jul 7, 2018
tests Fix path issue in tests Nov 26, 2017
.appveyor.yml Use cibuildwheel to build wheels Jul 7, 2018
.gitignore Update stub package Jun 7, 2018
.gitmodules Initial commit Nov 16, 2017
.travis.yml update pip on travis Apr 23, 2019
LICENSE Add LICENSE, update README, provide c file Nov 24, 2017
MANIFEST.in Add headers to build Jun 27, 2018
README.md Update README Apr 23, 2019
pyproject.toml Update for PEP 517 Apr 23, 2019
pytest.ini Root dir should be tests/ Nov 17, 2017
setup.py Use cibuildwheel to build wheels Jul 7, 2018
test-requirements.txt

README.md

pynanosvg

NOTE: nanosvg is no longer actively maintained

Travis | AppVeyor

Pynanosvg is a wrapper around nanosvg a simple svg parsing library. I created pynanosvg because the only other options in Python were the librsvg bindings, which are very large!

Install

Simple:

git clone --recursive https://github.com/ethanhs/pynanosvg.git
cd pynanosvg
python3 -m pip install .

or just

python3 -m pip install pynanosvg

Usage

The following parses an SVG file, rasterizes it, and saves it as a PNG

# import things
from svg import Parser, Rasterizer, SVG
from PIL import Image  # for saving rasterized image
# Parse from a file
svg = Parser.parse_file('my_cool_img.svg')
print('Image is {} by {}.'.format(svg.width, svg.height))
rast = Rasterizer()
buff = rast.rasterize(svg, svg.width, svg.height)
im = Image.frombytes('RGBA', svg.width, svg.height, buff)
im.save('my_cool_img.png')  # save the converted image!
You can’t perform that action at this time.