This helped me use For Loop to resize images using PIL. The PRODUCT variable is a list that contains all the product names, but you can also use readlines () for each line in the file:
def resize_images(self): products = PRODUCTS for name in products: try: fp = open(filename + name + ".jpg", "rb") img = Image.open(fp) img.load() img.save(filename + name + "_2" + ".jpg", quality=23) fp.close() except: print name
Aaron lelevier
source share