From 269269c66eaef3a3af37e3883b685e659a1004b0 Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Thu, 15 May 2025 12:24:33 +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=BF=D0=BE=D0=B4=D1=81=D1=87=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image_compressor.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/image_compressor.py b/image_compressor.py index 4864877..4fbd289 100644 --- a/image_compressor.py +++ b/image_compressor.py @@ -162,8 +162,8 @@ def compress_with_external( inject_exif(tmp_path, exif) tmp_path.replace(path) return True, path - logging.info( - f"Пропущено (не уменьшилось): {path} ({original_size // 1024}KB)" + logging.error( + f"Не удалось сжать (не уменьшилось): {path} ({original_size // 1024}KB)" ) tmp_path.unlink() return False, path @@ -194,8 +194,8 @@ def compress_with_pillow(path: Path) -> Tuple[bool, Path]: if temp_path.stat().st_size < original_size: temp_path.replace(path) return True, path - logging.info( - f"Пропущено (не уменьшилось): {path} ({original_size // 1024}KB)" + logging.error( + f"Не удалось сжать (не уменьшилось): {path} ({original_size // 1024}KB)" ) temp_path.unlink() except Exception as e: @@ -273,17 +273,12 @@ def compress_image(path: Path, use_fallback: bool = False): total_new_size += new_size if result: - if new_size < original_size: - saved = original_size - new_size - total_saved_bytes += saved - percent = (1 - new_size / original_size) * 100 - logging.info( - f"Сжато: {path} ({original_size//1024}KB -> {new_size//1024}KB, {percent:.2f}%)" - ) - else: - logging.info( - f"Пропущено (не уменьшилось): {path} ({original_size // 1024}KB)" - ) + saved = original_size - new_size + total_saved_bytes += saved + percent = (1 - new_size / original_size) * 100 + logging.info( + f"Сжато: {path} ({original_size//1024}KB -> {new_size//1024}KB, {percent:.2f}%)" + ) h = file_hash(final_path) with db_lock: @@ -312,7 +307,7 @@ def compress_image(path: Path, use_fallback: bool = False): processed_hashes.add(h) processed_count += 1 else: - skipped_count += 1 + error_count += 1 except Exception as e: error_count += 1