svg转png

svg转png,第1张

pip install cairosvg
from cairosvg import svg2png
import xml.etree.ElementTree as ET
import requests

#read xml file
url = 'https://xxx/230.xml'
response = requests.get(url)
print(response.text, type(response.text), type(response.content))
root = ET.fromstring(response.content)
print(type(root), root)
root.set('width', '407')
root.set('height', '595')
root.set('viewBox', "28.403526 284.768012 15.805359474999996 23.061548775")
print(root, root.get('viewBox'))
tree = ET.ElementTree(root)
root = tree.getroot()

for child in root.iter():
    print('tag:', child.tag)
    print('text:', child.text)
    print('attrib:', child.attrib)

print('*********************************')

for child in root:
    print('tag:', child.tag)
    print('text:', child.text)
    print('attrib:', child.attrib)

svg_code = ET.tostring(root)
print(svg_code)
svg2png(bytestring=svg_code, write_to='output1.png')

参考资料
Python 图片格式转换
Python将SVG转换成PNG图像
Python 如何将svg转换成png图片
python svg数据转图片
Python3 SVG 转 PDF PNG JPG 等格式文件
svglib的Python项目详细描述
Documentation
7 坐标系、变换和单位
Python完成SVG转PNG格式
python读写xml文件
Python 标准库之 xml.etree.ElementTree
(二)Python创建、修改、保存XML文件——xml.etree.ElementTree模块
关于xml:lxml隐藏根
svg命名空间
使用lxml从python中的xml中删除名称空间和前缀

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/722985.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存