feat: 适配macOS

This commit is contained in:
Zhang Muyu
2023-09-19 00:39:49 +08:00
parent fc439203ae
commit a4d8570078
2 changed files with 14 additions and 4 deletions

View File

@@ -1,4 +1,6 @@
svgwrite
cairosvg
lxml
pillow==9.5.0
pillow==9.5.0
svglib
rlPyCairo

View File

@@ -10,6 +10,9 @@ import json
from PIL import Image
from lxml import etree
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
from utils.font_size import *
from utils.image import *
from components.text import *
@@ -185,8 +188,12 @@ with open(svg_file_path, 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
# save as png
cairosvg.svg2png(url=svg_file_path, write_to=png_file_path)
# os.remove(svg_file_path)
# cairosvg.svg2png(url=svg_file_path, write_to=png_file_path)
drawing = svg2rlg(svg_file_path)
renderPM.drawToFile(drawing, png_file_path, fmt='PNG')
os.remove(svg_file_path)
# additional element
# open the image
@@ -197,5 +204,6 @@ src = src.resize((int(exit_height), int(exit_height)))
src_x = int((content_width - exit_height) / 2)
src_y = int(content_height - space_size - safe_area_size - exit_height)
dst.paste(src, (src_x, src_y))
dst = set_alpha(dst, 1)
dst = dst.convert('RGBA')
dst = set_alpha(dst, 0.75)
dst.save(png_file_path)