Convert SVG to png or other?

不想你离开。 提交于 2019-12-07 05:36:12

问题


Since it's very easy to display the content of a SVG file inside the iPython notebook, is there also a way (easy too) to get what we see inside a png file or other ?

from IPython.display import SVG
SVG(filename='../images/python_logo.svg')

If I do svg = SVG(filename='../images/python_logo.svg')

How can I save it to a png file ?


回答1:


SVG are vectors images (the drawings are saved as commands to draw lines, circles, etc). PNGs are bitmaps. So to convert SVG to PNG, you need a renderer.

The most obvious solution is ImageMagick, a library you have already installed, as it is used in several programs. A less obvious approach is using Inkscape. Using the commandline options, it's possible to use Inkscape as a conversion program. As Inkscape is vector oriented, I suspect quality to be better than ImageMagick (which is more bitmap-minded).

As a vector image (SVG) is a text file containing drawing instructions, it's easier to understand. PNGs contain just pixel information, and, to make things worse, they are compressed with a fairly complicated algorithm. Making sense of them is not as easy.

Have a look at the Inkscape man page, it's fairly obvious how to use it. This is the IMagick convert help.



来源:https://stackoverflow.com/questions/30302331/convert-svg-to-png-or-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!