I have more than 5000 pictures taken with several different cameras. They do not have the same resolutions, the same naming scheme and the pictures are too large to be used as is in a gallery.
The following code will make the images more uniform:
These images will then be used to make a gallery with gallerydeluxe.
#! /usr/bin/env python
import pathlib
from PIL import Image, ImageOps
from PIL.ExifTags import Base
dirs = ["src"]
dst = "all"
for dir in dirs:
p = pathlib.Path(dir)
for fname in p.iterdir():
img = Image.open(fname)
img = ImageOps.exif_transpose(img)
date = img.getexif()[Base.DateTime]
newfname = f"{dst}/{date.replace(':', '').replace(' ', '')}_{dir}.webp"
res = Image.new(img.mode, img.size)
res.putdata(list(img.getdata()))
x, y = img.size
if x > y:
f = x/1280.0
x = 1280
y = int(y/f)
else:
f = y/1280.0
y = 1280
x = int(x/f)
res = res.resize((x, y), Image.LANCZOS)
res.save(newfname, 'webp')