commit 5b049428235a8438c27ddd513524fb5cfb1db74e Author: jetsparrow Date: Mon Sep 15 01:15:11 2025 +0300 Python script to combine appropriately named scans into .pdf documents (by Basique) diff --git a/combine-scans.py b/combine-scans.py new file mode 100644 index 0000000..1e0bdcf --- /dev/null +++ b/combine-scans.py @@ -0,0 +1,34 @@ +import PIL.Image +import os + +import re + +import natsort + +p1 = re.compile("(.+)(\\.|-)(\\d)\\.jpe?g") + +digits = re.compile("\\d+") + +mappe = {} + +everything = [] + +for f in natsort.natsorted(os.listdir(".")): + if not (f.endswith(".jpeg") or f.endswith(".jpg")): + continue + + match = p1.match(f) + flat = match.group(1) + + if flat not in mappe: + mappe[flat] = [] + + img = PIL.Image.open(f) + mappe[flat].append(img) + everything.append(img) + +for flat in mappe: + mappe[flat][0].save(f"out/{flat}.pdf", save_all=True, append_images=mappe[flat][1:]) + print(flat) + +everything[0].save("out/everything.pdf", save_all=True, append_images=everything[1:]) \ No newline at end of file