Skip to content

Instantly share code, notes, and snippets.

@rudmanmrrod
Created November 27, 2017 11:59
Show Gist options
  • Save rudmanmrrod/635e522e262cf48cfbee7d6ddb98b666 to your computer and use it in GitHub Desktop.
Save rudmanmrrod/635e522e262cf48cfbee7d6ddb98b666 to your computer and use it in GitHub Desktop.
Transforma imagen webp a jpg
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