From dc99fcf50f1a53b97310a4b899d37f2cccdbdd8d Mon Sep 17 00:00:00 2001 From: Zhang Muyu Date: Sun, 1 Oct 2023 21:09:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mac=E8=BE=93=E5=87=BApng=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E5=BA=A6=E9=97=AE=E9=A2=98.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/io.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/io.py b/utils/io.py index 925e5c2..81bb8f6 100644 --- a/utils/io.py +++ b/utils/io.py @@ -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)