diff --git a/app/services/__pycache__/image_service.cpython-312.pyc b/app/services/__pycache__/image_service.cpython-312.pyc index 146cc59..a92981c 100644 Binary files a/app/services/__pycache__/image_service.cpython-312.pyc and b/app/services/__pycache__/image_service.cpython-312.pyc differ diff --git a/app/services/image_service.py b/app/services/image_service.py index 88c19e6..7b532c3 100644 --- a/app/services/image_service.py +++ b/app/services/image_service.py @@ -1,4 +1,6 @@ import os +from pathlib import Path + from fastapi import HTTPException from fastapi.responses import FileResponse from fastapi import APIRouter, Request, FastAPI @@ -27,6 +29,13 @@ class FileHandler: def dest_filename(self) -> str: base_url = "static/images/{category}/{image_type}/{filename}" return base_url.format( category = self.category, image_type = self.image_type, filename = self.filename ) + @property + def dest_filename_webp(self) -> str: + base_url = "static/images/{category}/{image_type}/{filename}" + path = Path( base_url.format( category = self.category, image_type = self.image_type, filename = self.filename ) ) + if path.suffix != ".webp": + path = path.with_suffix( ".webp" ) + return str(path) @property def dest_path(self) -> str: @@ -139,7 +148,8 @@ class ImageService: resized_img = img.resize( (width, height), Image.Resampling.LANCZOS ) os.makedirs(file_path.dest_path,exist_ok = True) resized_img.save( file_path.dest_filename ) - + resized_img.save( file_path.dest_filename_webp, format = "WEBP", quality = 90 ) # Adjust quality as needed + print(file_path.dest_filename_webp) async def get_image(self, category: str, type: str, filename: str): file_path = self._resolve_path( category, type, filename ) @@ -157,7 +167,7 @@ class ImageService: file_path = FileHandler(category = category,image_type = image_type,filename = filename) self.validate_image( file_path, width = width,height=height, overwrite = True ) - tag = f'