1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import os from PIL import Image
for root, dirs, files in os.walk("."): for bmpfig in files: if not bmpfig.endswith('.bmp') and not bmpfig.endswith('.png'): continue bmpfig = os.path.join(root, bmpfig) newfigname = bmpfig[:-4] + ".jpg" print "converting from", bmpfig, "to", newfigname img = Image.open(bmpfig) img = img.convert('RGB') img.save(newfigname, format='jpeg', quality=95) img.close() os.remove(bmpfig)
|