Created
November 27, 2017 11:59
-
-
Save rudmanmrrod/635e522e262cf48cfbee7d6ddb98b666 to your computer and use it in GitHub Desktop.
Transforma imagen webp a jpg
This file contains hidden or 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
import os, sys, imghdr | |
from PIL import Image | |
def change_files(directorio="."): | |
dirs = [x for x in os.listdir(directorio) if ".webp" in x] | |
for image in dirs: | |
im = Image.open(directorio+"/"+image).convert("RGB") | |
name = image.split(".")[0] | |
im.save(directorio+"/"+name+".jpg","jpeg") | |
print("Images converted") | |
if __name__ == '__main__': | |
filename = "." | |
if(len(sys.argv)>1): | |
filename = sys.argv[1] | |
if not os.path.exists(filename): | |
print("El directorio solicitado no existe") | |
try: | |
change_files(filename) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment