Skip to content

Instantly share code, notes, and snippets.

@marcostrinca
Last active December 11, 2022 06:40
Show Gist options
  • Save marcostrinca/8e7d4029bb3d987f9214c1d32728210c to your computer and use it in GitHub Desktop.
Save marcostrinca/8e7d4029bb3d987f9214c1d32728210c to your computer and use it in GitHub Desktop.
Resize all images in a folder using python
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()
@manza-ari
Copy link

why the code is not working for me? I want to resize multiple images in a folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment