Python/PIL Resize all images in a folder
python, python-imaging-library
Solution
#!/usr/bin/python
from PIL import Image
import os, sys
path = "/root/Desktop/python/images/"
dirs = os.listdir( path )
def resize():
for item in dirs:
if os.path.isfile(path+item):
im = Image.open(path+item)
f, e = os.path.splitext(path+item)
imResize = im.resize((200,200), Image.ANTIALIAS)
imResize.save(f + ' resized.jpg', 'JPEG', quality=90)
resize()
Your mistake is belong to full path of the files. Instead of item must be path+item
Problem
I have the following code that I thought would resize the images in the specified path But when I run it, nothing works and yet python doesn't throw any error so I don't know what to do. Please advise. Thanks. ``` from PIL import Image import os, sys path = ('C:\Users\Maxxie\color\complete') def resize(): for item in os.listdir(path): if os.path.isfile(item): im = Image.open(item) f, e = os.path.splitext(item) imResize = im.resize((200,200), Image.ANTIALIAS) imResize.save(f + ' resized.jpg', 'JPEG', quality=90) resize() ```