Skip to content

Instantly share code, notes, and snippets.

@go4Mor4
Last active February 14, 2020 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save go4Mor4/d3e4c27ce51ec7b547673c23838f4df8 to your computer and use it in GitHub Desktop.
Save go4Mor4/d3e4c27ce51ec7b547673c23838f4df8 to your computer and use it in GitHub Desktop.
from PIL import Image
import os
import argparsedef rescale_images(directory, size):
for img in os.listdir(directory):
im = Image.open(directory+img)
im_resized = im.resize(size, Image.ANTIALIAS)
im_resized.save(directory+img)if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Rescale images")
parser.add_argument('-d', '--directory', type=str, required=True, help='Directory containing the images')
parser.add_argument('-s', '--size', type=int, nargs=2, required=True, metavar=('width', 'height'), help='Image size')
args = parser.parse_args()
rescale_images(args.directory, args.size)
#python transform_image_resolution.py -d images/ -s 800 600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment