Python将svg转换为png [英] Python convert svg to png

查看:122
本文介绍了Python将svg转换为png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我必须将svg文件转换为png或gif,但我不知道它是否可能,有人知道这样做的方式吗?我需要将svg文件转换为png或gif的原因是因为我想上传它,但网站dosnt支持svg的。



我在Windows 7上使用python 3.5



我怀疑来源会提供更好的回复但是如果你认为你需要代码我可以发布一个链接到pastebin或其他东西。



我尝试过:



我曾尝试使用cairosvg,但我遇到了一堆错误,所以我可能会做错了,文档对我来说都不够。

我也查了pycairo但是我没有理解安装程序...

Hello, I have to convert svg files into png or gif but I dont know if it's even possible, do anyone know a way thi achive this? the reason I need to convert the svg file to png or gif is because I want to upload it but the site dosnt support svg's.

Im using python 3.5 on windows 7

I doubt the source would provide improved answeres but if you think you need the code I can post a link to pastebin or something.

What I have tried:

Ive tryed cairosvg but I just got a bunch of errors so I might be doing it all wrong, the documentation were insufficent for me.
I also checked pycairo but I didnt understand the installation procedure...

推荐答案

您的问题与您使用Windows的事实有关。虽然有多个库和工具可以用Linux执行转换(包括Python包装器),但这些可能不适用于Windows或难以设置。



最简单的解决方案将从Python(os.system或subprocess.call)中调用命令行工具。一个准备使用Windows可执行文件的候选人将是 ImageMagick:从二进制分发安装 [ ^ ]。您还可以使用Windows版本的 Inkscape [ ^ ]为转换提供命令行选项而无需启动GUI。
Your problems are related to the fact that you are using Windows. While there are multiple libraries and tools to perform the conversion with Linux (including Python wrappers), these may be not available for Windows or difficult to setup.

The simplest solution would be calling a command line tool from within Python (os.system or subprocess.call). One candidate providing ready to use Windows executables would be ImageMagick: Install from Binary Distribution[^]. You can also use the Windows version of Inkscape[^] which provides command line options for conversions without starting the GUI.


这篇关于Python将svg转换为png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆