# -*- coding: utf-8 -*- """ Created on Thu May 03 13:13:56 2018 @author: haaksma """ ### Set up modules import os from shutil import move from PIL import Image ### File locations image_dirs = os.getcwd() for root, dirs, files, in os.walk(image_dirs): for file in files: if file.endswith('.jpg'): # open file path = os.path.join(root, file) img = Image.open(path) # crop file #area = (440, 340, 2700, 1800) area = (820, 675, 5100, 3438) cropped_img = img.crop(area) # in debug mode this can be used to show jpg files: cropped_img.show() new_width = 900 new_height = 581 # create and save new file img1 = cropped_img.resize((new_width, new_height), Image.ANTIALIAS) img1.save(path) print "we cropped and saved jpg: ", file else: continue