Исправлено отображение изменение веса файла

This commit is contained in:
2025-05-16 03:35:19 +03:00
parent 7c83145baf
commit 436611a5b4

View File

@@ -131,24 +131,24 @@ def convert_png_to_jpeg(path: Path) -> Optional[Path]:
def compress_with_external( def compress_with_external(
path: Path, ext: str path: Path, ext: str
) -> Tuple[Optional[bool], Path]: ) -> Tuple[Optional[bool], Path]:
exif = extract_exif(path)
original_size = path.stat().st_size original_size = path.stat().st_size
tmp_path = path.with_name(path.stem + ".compressed" + path.suffix) tmp_path = path.with_name(path.stem + ".compressed" + path.suffix)
exif = extract_exif(path)
try: try:
if ext == ".png": if ext == ".png":
converted = convert_png_to_jpeg(path) converted = convert_png_to_jpeg(path)
if not converted: if not converted:
return False, path return False, path
conerted_size = converted.stat().st_size converted_size = converted.stat().st_size
logging.warning( logging.warning(
f"Сконвертирован PNG в JPEG: {path} ({original_size // 1024} KB) -> {converted} ({conerted_size // 1024} KB)" f"Сконвертирован PNG в JPEG: {path} ({original_size // 1024} KB) -> {converted} ({converted_size // 1024} KB)"
) )
if conerted_size < TARGET_SIZE: if converted_size <= TARGET_SIZE:
return True, converted return True, converted
path = converted path = converted
ext = ".jpg" ext = ".jpg"
original_size = conerted_size original_size = converted_size
if ext in [".jpg", ".jpeg"]: if ext in [".jpg", ".jpeg"]:
tool = get_tool_path("cjpeg-static.exe") tool = get_tool_path("cjpeg-static.exe")
args_base = [ args_base = [
@@ -217,9 +217,9 @@ def compress_with_external(
def compress_with_pillow(path: Path) -> Tuple[bool, Path]: def compress_with_pillow(path: Path) -> Tuple[bool, Path]:
exif = extract_exif(path)
original_size = path.stat().st_size original_size = path.stat().st_size
tmp_path = path.with_name(path.stem + ".pillowtmp" + path.suffix) tmp_path = path.with_name(path.stem + ".pillowtmp" + path.suffix)
exif = extract_exif(path)
try: try:
with Image.open(path) as img: with Image.open(path) as img: