From 5b049428235a8438c27ddd513524fb5cfb1db74e Mon Sep 17 00:00:00 2001 From: jetsparrow Date: Mon, 15 Sep 2025 01:15:11 +0300 Subject: [PATCH] Python script to combine appropriately named scans into .pdf documents (by Basique) --- combine-scans.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 combine-scans.py 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