This commit is contained in:
parent
abc1c1c1ab
commit
b75d8dcb81
1 changed files with 16 additions and 0 deletions
16
server/szurubooru/func/psd_handler.py
Normal file
16
server/szurubooru/func/psd_handler.py
Normal 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()
|
Loading…
Reference in a new issue