From b75d8dcb81180991c8094de8fae75e2170ddfca2 Mon Sep 17 00:00:00 2001 From: recordcrash Date: Sat, 19 Oct 2024 19:35:58 +0200 Subject: [PATCH] --- server/szurubooru/func/psd_handler.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 server/szurubooru/func/psd_handler.py diff --git a/server/szurubooru/func/psd_handler.py b/server/szurubooru/func/psd_handler.py new file mode 100644 index 00000000..a36d8f7e --- /dev/null +++ b/server/szurubooru/func/psd_handler.py @@ -0,0 +1,16 @@ +from PIL import Image +from io import BytesIO + +def handle_psd_file(path: str) -> None: + with open(path, "rb") as f: + psd_content = f.read() + png_content = convert_psd_to_png(psd_content) + png_path = path.replace(".psd", ".png") + with open(png_path, "wb") as f: + f.write(png_content) + +def convert_psd_to_png(content: bytes) -> bytes: + img = Image.open(BytesIO(content)) + img_byte_arr = BytesIO() + img.save(img_byte_arr, format="PNG") + return img_byte_arr.getvalue()