alkator/resize_photos.py
2024-10-07 06:56:34 +02:00

14 lines
441 B
Python

import glob
import PIL.Image
photos = glob.glob('photos/2/*.jpg')
for image in photos:
print(image)
img = PIL.Image.open(image)
img.save(image.replace('.jpg', '.webp'))
ratio = 400/max(img.height, img.width)
img = img.resize((int(img.width * ratio), int(img.height * ratio)))
image = image.replace('photos/', 'photos/thumbnail/').replace('.jpg', '.webp')
img.save(image, quality=50, subsampling=2)