Resizing a lot of images quickly in paint or something similar takes a lot of time. This is a python script that resizes the .jpg images in a specified folder. Several differently dimensioned images can be generated for each original image and can be differentiated by the postfix associated with each size.
The script is called as:
python batchresize.py foldertoconvert
where batchresize.py is the script displayed below.
The resized images are dumped into the directory the script is already in.
#configure dimensions to resize images postfixs = ['thumb' ,'large' ,'small' ] heights = [105 ,600 ,300 ] widths = [140 ,800 ,400 ] #---------------------------------------------------------------------- from os import listdir from PIL import Image # requires PIL import sys #get the directory full of images to process path = sys.argv[1] #get the names files in directory contents = listdir(path) for item in contents: #make sure the file extention is a .jpg if item[-4:] != '.jpg': continue #get a path to the original image filepath = path + '/' + item #generate a scaled version of the image for each column in config #table for idx, postfix in enumerate(postfixs): height = heights[idx] width = widths[idx] img = Image.open(filepath) img = img.resize((width, height), Image.ANTIALIAS) newpath = item[:-4] + '_' + postfix + '.jpg' img.save(newpath, 'JPEG', quality=90)