Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from PIL import Image
import sys
import os
try:
im = None
for root, dirs, files in os.walk("."):
for filename in files:
if filename.endswith('.jpg'):
im = Image.open(filename).convert("RGB")
im.save(filename.replace('jpg', 'png'), "png")
elif filename.endswith('.png'):
im = Image.open(filename).convert("RGB")
im.save(filename.replace('png', 'jpg'), "jpeg")
else:
print('dont have image to convert')
except IOError:
print('directory empty!')
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment