Skip to content

Instantly share code, notes, and snippets.

@Shivam60
Created February 21, 2019 09:41
Show Gist options
  • Save Shivam60/39659affa7381c2cdf58232f3fa8076c to your computer and use it in GitHub Desktop.
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.
'''
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