Last active
December 11, 2022 06:40
-
-
Save marcostrinca/8e7d4029bb3d987f9214c1d32728210c to your computer and use it in GitHub Desktop.
Resize all images in a folder using python
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
import os, sys | |
from PIL import Image | |
h = 256 | |
w = 144 | |
in_dir = "./input_dir/" | |
out_dir = "./output_dir/" | |
dirs = os.listdir( in_dir ) | |
def resize(): | |
for item in dirs: | |
if os.path.isfile(in_dir+item): | |
im = Image.open(in_dir+item) | |
f, e = os.path.splitext(in_dir+item) | |
imResize = im.resize((w, h), Image.ANTIALIAS) | |
print(f) | |
imResize.save(out_dir + item, 'jpeg', quality=75) | |
resize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why the code is not working for me? I want to resize multiple images in a folder.