Created
February 2, 2022 06:32
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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