Python script to combine appropriately named scans into .pdf documents (by Basique)
This commit is contained in:
commit
5b04942823
34
combine-scans.py
Normal file
34
combine-scans.py
Normal file
@ -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:])
|
||||||
Loading…
Reference in New Issue
Block a user