1a82c2b ←12805caantonApr 23, 2026 api

create _run.py via macOS

A /docs/undefined +54 -0
A /docs/undefined +54 -0
1"""
2Image resize: reads all images, creates thumbnails and a contact sheet.
3"""
4import os
5from PIL import Image
6
7THUMB_SIZE = (256, 256)
8EXTENSIONS = {".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp"}
9
10images = sorted(
11 f for f in os.listdir(".")
12 if os.path.splitext(f)[1].lower() in EXTENSIONS
13)
14
15if not images:
16 print("No images found")
17 exit(0)
18
19os.makedirs("thumbs", exist_ok=True)
20
21thumbs = []
22report = ["# image processing report\n"]
23
24for fname in images:
25 img = Image.open(fname)
26 report.append(f"- {fname}: {img.size[0]}x{img.size[1]}, {img.mode}")
27
28 # create thumbnail
29 thumb = img.copy()
30 thumb.thumbnail(THUMB_SIZE)
31 thumb_path = f"thumbs/{os.path.splitext(fname)[0]}_thumb.png"
32 thumb.save(thumb_path, "PNG")
33 thumbs.append(thumb)
34
35# create contact sheet (grid of thumbnails)
36if thumbs:
37 cols = min(4, len(thumbs))
38 rows = (len(thumbs) + cols - 1) // cols
39 sheet = Image.new("RGB", (cols * THUMB_SIZE[0], rows * THUMB_SIZE[1]), (255, 255, 255))
40 for i, thumb in enumerate(thumbs):
41 x = (i % cols) * THUMB_SIZE[0]
42 y = (i // cols) * THUMB_SIZE[1]
43 # center thumbnail in its cell
44 ox = (THUMB_SIZE[0] - thumb.size[0]) // 2
45 oy = (THUMB_SIZE[1] - thumb.size[1]) // 2
46 sheet.paste(thumb, (x + ox, y + oy))
47 sheet.save("contact_sheet.png", "PNG")
48 report.append(f"\n## output\n- {len(thumbs)} thumbnails in thumbs/")
49 report.append(f"- contact sheet: {cols}x{rows} grid")
50
51with open("report.md", "w") as f:
52 f.write("\n".join(report))
53
54print(f"Done: processed {len(images)} images")