This commit is contained in:
recordcrash 2024-10-19 19:35:58 +02:00
parent abc1c1c1ab
commit b75d8dcb81

View file

@ -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()