/
DemienMedich
/
BodyweightBase
Обзор
Документация
Войти
/
DemienMedich
/
BodyweightBase
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
tools/optimize_mobile_exercise_frames.py
40 строк
2 KB
DemienMedich
Add hip flexor exercise catalog assets
09 июл 2026, 11:29
09 июл 2026, 11:29
34b566c
Код
Авторство
О чём код?
from __future__ import annotations import argparse from pathlib import Path from PIL import Image def optimize(source: Path, destination: Path, max_edge: int, quality: int) -> tuple[int, int]: destination.mkdir(parents=True, exist_ok=True) written = 0 source_bytes = 0 for path in sorted(source.glob("*.png")): source_bytes += path.stat().st_size with Image.open(path) as image: image = image.convert("RGB") image.thumbnail((max_edge, max_edge), Image.Resampling.LANCZOS) image.save(destination / f"{path.stem}.jpg", "JPEG", quality=quality, optimize=True, progressive=True) written += 1 return written, source_bytes def main() -> None: parser = argparse.ArgumentParser(description="Create compact Android exercise frames.") parser.add_argument("--source", type=Path, default=Path("Assets/ExerciseFrames")) parser.add_argument("--destination", type=Path, default=Path("Assets/ExerciseFramesMobile")) parser.add_argument("--max-edge", type=int, default=720) parser.add_argument("--quality", type=int, default=78) args = parser.parse_args() count, source_bytes = optimize(args.source, args.destination, args.max_edge, args.quality) output_bytes = sum(path.stat().st_size for path in args.destination.glob("*.jpg")) ratio = output_bytes / source_bytes if source_bytes else 0.0 print(f"Optimized {count} frames: {source_bytes / 1048576:.1f} MB -> " f"{output_bytes / 1048576:.1f} MB ({ratio:.1%})") if __name__ == "__main__": main()