You've already forked ImageCompressor
mirror of
https://github.com/Llloooggg/ImageCompressor.git
synced 2026-03-06 03:26:23 +03:00
Исправление "исчезаующих" файлов
This commit is contained in:
@@ -123,8 +123,6 @@ def compress_with_external(
|
|||||||
converted = convert_png_to_jpeg(path)
|
converted = convert_png_to_jpeg(path)
|
||||||
if not converted:
|
if not converted:
|
||||||
return False, path
|
return False, path
|
||||||
if converted.stat().st_size <= TARGET_SIZE:
|
|
||||||
return True, converted
|
|
||||||
path = converted
|
path = converted
|
||||||
ext = ".jpg"
|
ext = ".jpg"
|
||||||
original_size = path.stat().st_size
|
original_size = path.stat().st_size
|
||||||
@@ -178,15 +176,18 @@ def compress_with_external(
|
|||||||
return False, path
|
return False, path
|
||||||
|
|
||||||
if tmp_path.exists():
|
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:
|
if exif:
|
||||||
inject_exif(tmp_path, exif)
|
inject_exif(tmp_path, exif)
|
||||||
tmp_path.replace(path)
|
tmp_path.replace(path)
|
||||||
return True, path
|
return True, path
|
||||||
|
else:
|
||||||
logging.error(
|
logging.error(
|
||||||
f"Не удалось сжать внешней утилитой (не уменьшилось): {path} ({original_size // 1024} KB)"
|
f"Не удалось сжать внешней утилитой (не уменьшилось): {path} ({original_size // 1024} KB)"
|
||||||
)
|
)
|
||||||
tmp_path.unlink()
|
tmp_path.unlink()
|
||||||
|
|
||||||
return False, path
|
return False, path
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user