-
-
Save pije76/eff79746215c8e5f5e9eb5d4c1d75f7e to your computer and use it in GitHub Desktop.
SVG vector data to PNG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew upgrade | |
brew update | |
brew install cairo | |
brew install py2cairo | |
ln -s ~/Developer/lib/python2.7/site-packages/cairo ~/.virtualenvs/wpd/lib/python2.7/site-packages/cairo | |
# I needed to specify that my virtual environment uses python 2.7.3 because by default it used 2.7.2 | |
# but brew compiled py2cairo with 2.7.3 | |
mkvirtualenv --no-site-packages -p ~/Developer/bin/python wpd | |
pip install cairosvg | |
> from cairosvg import svg2png | |
> import base64 | |
> binary = svg2png(<svg data>) | |
> b64 = base64.b64encode(binary) | |
> print "data:image/png;base64,%s" % b64 | |
# The next steps are to pass this data to an ```<img>``` in an HTML template and render via [xhtml2pdf](https://github.com/chrisglass/xhtml2pdf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment