Python-124 用python转换图片格式 2021-09-28

  • 具体代码如下(只需要更改对应的目标文件路径和输出文件路径):

#pip install svglib
#参考:https://pypi.org/project/svglib/
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF, renderPM

drawing = svg2rlg("C:\\Users\\Administrator\\Downloads\\1.svg")
renderPDF.drawToFile(drawing, "C:\\Users\\Administrator\\Downloads\\file.pdf")
renderPM.drawToFile(drawing, "C:\\Users\\Administrator\\Downloads\\file.png", fmt="PNG")
renderPM.drawToFile(drawing, "C:\\Users\\Administrator\\Downloads\\file.JPEG", fmt="JPEG")
renderPM.drawToFile(drawing, "C:\\Users\\Administrator\\Downloads\\file.TIFF", fmt="TIFF")
print("Conversion is done! ")
转换结果如下:
image.png

你可能感兴趣的:(Python-124 用python转换图片格式 2021-09-28)