diff --git a/backend/utils.py b/backend/utils.py index b50b648..7f3bdfd 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -1,4 +1,5 @@ from PIL import Image, UnidentifiedImageError +from fastapi import HTTPException from pathlib import Path import io @@ -13,13 +14,13 @@ def image_normalize(img: bytes) -> bytes: img.save(byte_arr, format='WEBP') return byte_arr.getvalue() except UnidentifiedImageError: - return 0 + raise HTTPException(status_code=500, detail="Image file cannot be readed!") + def save_image(img: bytes, dir: str, name: str) -> int: path = asset(dir) path.mkdir(exist_ok=True) img = image_normalize(img) - if img: - with open(Path(path, name+'.webp'), "wb") as file: - file.write(img) - return len(img) \ No newline at end of file + with open(Path(path, name+'.jpg'), "wb") as file: + file.write(img) + return len(img)