Created
February 21, 2019 09:41
-
-
Save Shivam60/39659affa7381c2cdf58232f3fa8076c to your computer and use it in GitHub Desktop.
This functions resizes all the images for a given size in a given directory. It saves the output to another directory.
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
''' | |
ImageDir: all the images to bre resized are in this directory | |
SaveDir: resized images to be saved in this directory | |
TargetSize: New size of the images | |
''' | |
from PIL import Image | |
def resize(ImageDir,SaveDir,TargetSize): | |
p=os.getcwd() | |
os.chdir(ImageDir) | |
for imgs in os.listdir(): | |
image = Image.open(imgs) | |
new_image = image.resize(TargetSize) | |
new_image.save(SaveDir+r"/"+str(imgs)) | |
os.chdir(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment