Skip to content

Instantly share code, notes, and snippets.

@aaronjolson
Last active August 9, 2018 22:02
Show Gist options
  • Save aaronjolson/f8eef70a39f99829a417b521318f6d90 to your computer and use it in GitHub Desktop.
Save aaronjolson/f8eef70a39f99829a417b521318f6d90 to your computer and use it in GitHub Desktop.
Converts all png, tif, and bmp files in a directory into jpegs
import os
from PIL import Image
for infile in os.listdir("./"):
print ("file : " + infile)
if infile[-3:] == "tif" or infile[-3:] == "bmp" or infile[-3:] == "png":
outfile = infile[:-3] + "jpeg"
im = Image.open(infile)
print("new filename : " + outfile)
out = im.convert("RGB")
out.save(outfile, "JPEG", quality=90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment