I want to convert some base64 encoded png images to jpg using python. I know how to decode from base64 back to raw:
import base64
pngraw = base64.decodestring(p
Right from the PIL tutorial:
To save a file, use the save method of the Image class. When saving files, the name becomes important. Unless you specify the format, the library uses the filename extension to discover which file storage format to use.
import os, sys
import Image
for infile in sys.argv[1:]:
f, e = os.path.splitext(infile)
outfile = f + ".jpg"
if infile != outfile:
try:
Image.open(infile).save(outfile)
except IOError:
print "cannot convert", infile
So all you have to do is set the file extension to .jpeg
or .jpg
and it will convert the image automatically.