You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.4 KiB

In [4]:
from PIL import Image
import os
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'static/uploads/annotation-compass/')

def thumbnail(image):
    try:
        img = Image.open(image)
        img.thumbnail((128,128))
        name = image.rsplit('.', 1)[0]
        ext = image.rsplit('.', 1)[1]
        img.save(f'{name}_thumb.{ext}')
    except IOError:
        pass
    
files = os.listdir(UPLOAD_FOLDER)

for file in files:
    thumbnail(os.path.join(UPLOAD_FOLDER, file))
In [ ]: