问题

Question: Which reproducible process can enable Windows Python users to render a SVG image into PNG?

Many questions/answers (such as Convert SVG to PNG in Python and Server-side SVG to PNG (or some other image format) in python, which are not duplicates for the reasons explained below) explain how to convert a SVG to PNG with Python.

Unfortunately, none of them are ready-to-use for Python + Windows. After more than 20 minutes, and many different attempts, I'm still unable to do it.

More details about failing attempts:

Installing cairo on Windows is not straightforward, we have to use Gohlke's binaries Intalling pycairo with Python 3.7 on Windows :

pip install pycairo-1.20.0-cp37-cp37m-win_amd64.whl

Even once cairo is installed, rsvg (from main answers of Server-side SVG to PNG (or some other image format) in python, Convert SVG to PNG in Python) is not available for Windows:

pip install rsvg # or pyrsvg

> ERROR: No matching distribution found for pyrsvg

Solutions with svglib or reportlab don't work out-of-the-box on Python3 + Windows:

from svglib.svglib import svg2rlg

from reportlab.graphics import renderPDF, renderPM

drawing = svg2rlg("a.svg")

renderPM.drawToFile(drawing, "file.png", fmt="PNG")

Indeed:

AttributeError: 'Image' object has no attribute 'fromstring'

So a solution - specific for Windows - would be helpful.

回答1:

From the comments, the solution was to install svglib version 1.0.1 and reportlab 3.5.59.

来源:https://stackoverflow.com/questions/65759849/convert-svg-to-png-with-python-on-windows

python svg2rlg,Convert SVG to PNG with Python on Windows相关推荐

  1. python 爬取svg数据_python处理svg数据

    我感觉python不能直接处理svg格式,所以想把它转化为png数据. 昨天搞了一天,把svg转化为png格式,网上有专门的python插件,百度搜一下很多. 但是装好后,发现有一个包已知报错. dl ...

  2. python编辑svg文件_使用Python批量转换SVG文件为PNG或PDF文件

    使用Python批量转换SVG文件为PNG或PDF文件 使用Python批量转换SVG文件为PNG或PDF文件 使用模块 1 模块单独使用 2 模块用于代码 实例 1 命令行方式 2 python脚本 ...

  3. 【Python】使用Python对pdf,svg,png等进行转换

    Technicalflight转换工具使用Python对pdf,svg,png等进行转换 代码开源在Github:https://github.com/Technicalflight/Python-T ...

  4. python svg2rlg_python – 从svg转换为pdf

    我正在尝试使用以下代码将svg文件转换为pdf,但出现错误 SRC: from svglib.svglib import svg2rlg from reportlab.graphics import ...

  5. python 脚本将视频转化成图片 | python scripts to convert video to pictures

    python 脚本将视频转化成图片 | python scripts to convert video to pictures python video_to_images.py 运行时,修改输入.输 ...

  6. python编辑svg文件_使用Python创建SVG

    我正在构建一组包含不幸数量的硬编码值的SVG文件(它们必须打印一些大小为mm的元素,而其他元素必须按百分比缩放,并且大多数值是相对于彼此定义的).而不是手工管理这些数字(天堂禁止我想改变一些东西),我 ...

  7. python invalid type promotion_17个新手常见Python运行时错误

    当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif, else, for, wh ...

  8. python用中文怎么说-如何实现python设置中文界面?

    下面,小编将通过一组实例演示,让大家更直观,更清楚明白的了解要设置中文这一内容的操作步骤. 首先展示实例代码:import pygame from pygame.locals import * def ...

  9. python编写程序-30分钟学会用Python编写简单程序

    参与文末每日话题讨论,赠送异步新书 异步图书君 学习目标 知道有序的软件开发过程的步骤. 了解遵循输入.处理.输出(IPO)模式的程序,并能够以简单的方式修改它们. 了解构成有效Python标识符和表 ...

最新文章

  1. 为什么阿里巴巴禁止使用BigDecimal的equals方法做等值比较?
  2. 【pytorch】torch.nn.GroupNorm的使用
  3. api网关选型_如何轻松打造百亿流量API网关?看这一篇就够了(下)
  4. 开发顺序工作流时注意的几个事项
  5. webpack入门+react环境配置
  6. python中randn函数_numpy常用函数之randn
  7. springcloud 消息队列_全面而且简洁介绍SpringCloud微服务
  8. python一行代码打印Love心形
  9. java nature_Java中BufferedReader和scanner的对比 - nature
  10. SurfaceView闪烁问题
  11. JavaScript判断浏览器 Browser detect
  12. Uniform Distribution均匀分布
  13. 读书笔记∣商务与经济统计Ch.1-3
  14. 237.删除链表中的节点
  15. 算法导论(原书第三版)答案与学习笔记(一)
  16. oracle密码过期修改
  17. 第3.1~3.3节《合成孔径雷达成像原理-皮亦鸣》
  18. 你的编程能力从什么时候开始突飞猛进?
  19. html页面百度分享代码,使用百度分享api实现网页分享功能代码
  20. Swift网络请求框架Moya的使用

热门文章

  1. 【JZOJ A组】风筝
  2. C语言 | 10 结构体与共同体
  3. 微型计算机中常见到的Ega.VGA等是指,2011年计算机一级考试理论试题:第七部分单选题7...
  4. Linux常用命令_top
  5. STM32实现按键有限状态机(超详细,易移植)
  6. 罗爷:创新法律服务交易模式 找到你的专属lawyer
  7. 帝国CMS7.5开发的小说源码自适应网站源码
  8. dell 重装linux系统_DELL服务器安装linux 系统
  9. Vue项目实战之人力资源平台系统(七)员工管理模块
  10. 解决VMware虚拟机无法访问主机mysql的问题