optimize.py 443 B

123456789101112131415161718192021
  1. #!/usr/bin/env python3
  2. import glob
  3. import os
  4. import subprocess
  5. bmps = glob.glob("*.bmp")
  6. for i in bmps:
  7. subprocess.run(["convert",i,"png32:"+i.replace(".bmp",".png")])
  8. bmp_size = os.stat(i).st_size
  9. png_size = os.stat(i.replace(".bmp",".png")).st_size
  10. if bmp_size >= png_size:
  11. print(f"{i}: keeping png")
  12. os.remove(i)
  13. else:
  14. print(f"{i}: keeping bmp")
  15. os.remove(i.replace(".bmp",".png"))