From 5fcce98583db8d7184106ad1ca8db662297a0290 Mon Sep 17 00:00:00 2001 From: jimi <1847930177@qq.com> Date: Mon, 9 Mar 2026 14:57:41 +0800 Subject: [PATCH] fix: normalize animated images before gemini --- services/service_auto_image_pipeline.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/service_auto_image_pipeline.py b/services/service_auto_image_pipeline.py index e7878fd..0cbc7b4 100644 --- a/services/service_auto_image_pipeline.py +++ b/services/service_auto_image_pipeline.py @@ -110,11 +110,18 @@ class AutoImagePipelineService: @staticmethod def _normalize_image_for_gemini(image_path: Path) -> Path: suffix = image_path.suffix.lower() - if suffix not in {".avif", ".webp"}: - return image_path - - normalized_path = image_path.with_suffix(".jpg") with Image.open(image_path) as img: + is_animated = bool(getattr(img, "is_animated", False)) or int(getattr(img, "n_frames", 1) or 1) > 1 + needs_convert = suffix in {".avif", ".webp", ".gif"} or is_animated or img.mode not in ("RGB", "L") + if not needs_convert: + return image_path + + normalized_path = image_path.with_suffix(".jpg") + if is_animated: + try: + img.seek(0) + except Exception: + pass if img.mode not in ("RGB", "L"): img = img.convert("RGB") img.save(normalized_path, format="JPEG", quality=95)