Created
July 25, 2020 15:18
-
-
Save akarsh1995/637d78d6e1782921dad5c405f4a6df59 to your computer and use it in GitHub Desktop.
Create thumbnail for all the images in a directory.
This file contains hidden or 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
| SIZE_THUMBS = (75, 75) | |
| FROM_DIR = 'images' | |
| TO_DIR = 'thumbs' | |
| if __name__ == '__main__': | |
| import os | |
| if not os.path.exists(TO_DIR): | |
| os.mkdir(TO_DIR) | |
| import glob | |
| for filename in glob.glob(FROM_DIR + "/*.*p*g"): | |
| filename_thumbnail = os.path.join(TO_DIR, os.path.split(filename)[1]) | |
| print('{} -> {}'.format(filename, filename_thumbnail)) | |
| from PIL import Image | |
| im = Image.open(filename) | |
| im.thumbnail(SIZE_THUMBS) | |
| im.save(filename_thumbnail) |
This file contains hidden or 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
| Pillow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment