From 9de00280ed26c002bb95cef93c36558f2f4de2ed Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Thu, 15 May 2025 22:17:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20"=D0=B8=D1=81=D1=87=D0=B5=D0=B7?= =?UTF-8?q?=D0=B0=D1=83=D1=8E=D1=89=D0=B8=D1=85"=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image_compressor.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/image_compressor.py b/image_compressor.py index a9f1980..28abfe6 100644 --- a/image_compressor.py +++ b/image_compressor.py @@ -123,8 +123,6 @@ def compress_with_external( converted = convert_png_to_jpeg(path) if not converted: return False, path - if converted.stat().st_size <= TARGET_SIZE: - return True, converted path = converted ext = ".jpg" original_size = path.stat().st_size @@ -178,15 +176,18 @@ def compress_with_external( return False, path if tmp_path.exists(): - if tmp_path.stat().st_size < original_size: + new_size = tmp_path.stat().st_size + if new_size < original_size: if exif: inject_exif(tmp_path, exif) tmp_path.replace(path) return True, path - logging.error( - f"Не удалось сжать внешней утилитой (не уменьшилось): {path} ({original_size // 1024} KB)" - ) - tmp_path.unlink() + else: + logging.error( + f"Не удалось сжать внешней утилитой (не уменьшилось): {path} ({original_size // 1024} KB)" + ) + tmp_path.unlink() + return False, path