fix: mac输出png透明度问题.

This commit is contained in:
Zhang Muyu
2023-10-01 21:09:34 +08:00
parent 27b2d8d1d5
commit dc99fcf50f

View File

@@ -4,6 +4,7 @@ from lxml import etree
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
from utils.platform import *
from settings import *
def svg2png(dwg, content_width, content_height, svg_file_path, png_file_path):
dwg.save()
@@ -30,7 +31,12 @@ def svg2png(dwg, content_width, content_height, svg_file_path, png_file_path):
cairosvg.svg2png(url=svg_file_path, write_to=png_file_path)
elif is_darwin():
drawing = svg2rlg(svg_file_path)
renderPM.drawToFile(drawing, png_file_path, fmt='PNG')
image = renderPM.drawToPIL(d=drawing, bg=0xff00ff)
image = image.convert('RGBA')
data = image.getdata()
new_data = [(255, 255, 255, 0) if item[:3] == (255, 0, 255) else item for item in data]
image.putdata(new_data)
image.save(png_file_path, fmt='PNG')
else:
exit(-1)