convertDynamic.py 541 B

12345678910111213141516171819
  1. from PIL import Image
  2. import sys
  3. import os
  4. try:
  5. im = None
  6. for root, dirs, files in os.walk("."):
  7. for filename in files:
  8. if filename.endswith('.jpg'):
  9. im = Image.open(filename).convert("RGB")
  10. im.save(filename.replace('jpg', 'png'), "png")
  11. elif filename.endswith('.png'):
  12. im = Image.open(filename).convert("RGB")
  13. im.save(filename.replace('png', 'jpg'), "jpeg")
  14. else:
  15. print('dont have image to convert')
  16. except IOError:
  17. print('directory empty!')
  18. sys.exit()