I wrote the following code (based on code provided in the PIL documentation) to halve the size of all jpeg images in a folder and save as a new file. Not the fastest code, but it worked pretty well.
from PIL import Imageimport glob, os
newPath = raw_input("folder to process:") os.chdir(newPath) for infile in glob.glob("*.jpg"):file, ext = os.path.splitext(infile)im = Image.open(infile)print filex = int(im.size[0]*0.5)y = int(im.size[1]*0.5)size = x,yim.resize(size, Image.ANTIALIAS)im.save(file + "_small_" + ".jpg")
Leave a Reply