Last active
May 9, 2020 13:08
-
-
Save karthick965938/432d189d617824d4960175dea9403243 to your computer and use it in GitHub Desktop.
Python script for convert image resolution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import os | |
import argparse | |
def 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) | |
##run this command | |
##python convert_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