代码提交
This commit is contained in:
1 parent
49af497085
commit
3eb307c5c5
155 files changed
+4706
-100
No files matched your search
@@ -0,0 +1,30 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent / "rendered-user"
|
||||
PAGES = ROOT / "pages"
|
||||
OUT = ROOT / "contact-sheets"
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
font = ImageFont.truetype(r"C:\Windows\Fonts\arialbd.ttf", 28)
|
||||
page_paths = sorted(PAGES.glob("page-*.png"))
|
||||
|
||||
for sheet_index in range(0, len(page_paths), 4):
|
||||
group = page_paths[sheet_index:sheet_index + 4]
|
||||
images = [Image.open(path).convert("RGB") for path in group]
|
||||
page_w, page_h = images[0].size
|
||||
gutter, label_h = 48, 52
|
||||
sheet = Image.new("RGB", (page_w * 2 + gutter * 3, (page_h + label_h) * 2 + gutter * 3), "#D7DEE5")
|
||||
draw = ImageDraw.Draw(sheet)
|
||||
for index, (path, image) in enumerate(zip(group, images)):
|
||||
col, row = index % 2, index // 2
|
||||
x = gutter + col * (page_w + gutter)
|
||||
y = gutter + row * (page_h + label_h + gutter)
|
||||
draw.text((x, y), path.stem, font=font, fill="#172A3A")
|
||||
sheet.paste(image, (x, y + label_h))
|
||||
first, last = sheet_index + 1, sheet_index + len(group)
|
||||
sheet.save(OUT / f"pages-{first:02d}-{last:02d}.jpg", quality=92, subsampling=0)
|
||||
|
||||
print(f"created {len(list(OUT.glob('*.jpg')))} contact sheets")
|
||||
Reference in new issue
Block a user