From 1823840456dfee214c0f8e881ce7a9dc9e3323ec Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Mon, 25 Aug 2025 09:03:28 +0800 Subject: [PATCH] feat: Disable image optimization in find_preview_file function for future configuration --- py/utils/file_utils.py | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/py/utils/file_utils.py b/py/utils/file_utils.py index 954ec223..eaa73065 100644 --- a/py/utils/file_utils.py +++ b/py/utils/file_utils.py @@ -27,33 +27,34 @@ def find_preview_file(base_name: str, dir_path: str) -> str: full_pattern = os.path.join(dir_path, f"{base_name}{ext}") if os.path.exists(full_pattern): # Check if this is an image and not already webp - if ext.lower().endswith(('.jpg', '.jpeg', '.png')) and not ext.lower().endswith('.webp'): - try: - # Optimize the image to webp format - webp_path = os.path.join(dir_path, f"{base_name}.webp") + # TODO: disable the optimization for now, maybe add a config option later + # if ext.lower().endswith(('.jpg', '.jpeg', '.png')) and not ext.lower().endswith('.webp'): + # try: + # # Optimize the image to webp format + # webp_path = os.path.join(dir_path, f"{base_name}.webp") - # Use ExifUtils to optimize the image - with open(full_pattern, 'rb') as f: - image_data = f.read() + # # Use ExifUtils to optimize the image + # with open(full_pattern, 'rb') as f: + # image_data = f.read() - optimized_data, _ = ExifUtils.optimize_image( - image_data=image_data, - target_width=CARD_PREVIEW_WIDTH, - format='webp', - quality=85, - preserve_metadata=False - ) + # optimized_data, _ = ExifUtils.optimize_image( + # image_data=image_data, + # target_width=CARD_PREVIEW_WIDTH, + # format='webp', + # quality=85, + # preserve_metadata=False + # ) - # Save the optimized webp file - with open(webp_path, 'wb') as f: - f.write(optimized_data) + # # Save the optimized webp file + # with open(webp_path, 'wb') as f: + # f.write(optimized_data) - logger.debug(f"Optimized preview image from {full_pattern} to {webp_path}") - return webp_path.replace(os.sep, "/") - except Exception as e: - logger.error(f"Error optimizing preview image {full_pattern}: {e}") - # Fall back to original file if optimization fails - return full_pattern.replace(os.sep, "/") + # logger.debug(f"Optimized preview image from {full_pattern} to {webp_path}") + # return webp_path.replace(os.sep, "/") + # except Exception as e: + # logger.error(f"Error optimizing preview image {full_pattern}: {e}") + # # Fall back to original file if optimization fails + # return full_pattern.replace(os.sep, "/") # Return the original path for webp images or non-image files return full_pattern.replace(os.sep, "/")