From a4d8570078e01005daa7da97b5d4c07c7b24b287 Mon Sep 17 00:00:00 2001 From: Zhang Muyu Date: Tue, 19 Sep 2023 00:39:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8DmacOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 4 +++- test/main.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5a95e37..da58f01 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ svgwrite cairosvg lxml -pillow==9.5.0 \ No newline at end of file +pillow==9.5.0 +svglib +rlPyCairo \ No newline at end of file diff --git a/test/main.py b/test/main.py index 125c518..48e7f1c 100644 --- a/test/main.py +++ b/test/main.py @@ -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) \ No newline at end of file