Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018ks2K99uqCZjAxvy7Rdj1R
29 lines
1.5 KiB
Python
29 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""I primi piani (story.closeups) da un foglio di Codex su magenta pieno con due disegni affiancati: toglie il
|
|
magenta, separa i due disegni sulla colonna vuota fra loro e le riduce di SCALA. Stampa i riquadri dei disegni ritagliati, per
|
|
misurare dove vanno i testi.
|
|
python3 tools/primo_piano.py assets/generated/libro-storia-infinita.png assets/closeups/libro-chiuso.png \\
|
|
assets/closeups/libro-aperto.png 0.42"""
|
|
import sys
|
|
from PIL import Image
|
|
|
|
src, left_out, right_out, scale = sys.argv[1], sys.argv[2], sys.argv[3], float(sys.argv[4])
|
|
im = Image.open(src).convert('RGBA')
|
|
px = im.load()
|
|
W, H = im.size
|
|
for y in range(H):
|
|
for x in range(W):
|
|
r, g, b, a = px[x, y]
|
|
# Il magenta e i bordi rosati che lascia intorno alle figure.
|
|
if r > 150 and b > 150 and g < 120 and abs(r - b) < 90: px[x, y] = (0, 0, 0, 0)
|
|
# Si taglia sulla colonna vuota più vicina al centro: i due disegni non stanno per forza nelle due metà esatte.
|
|
alpha = im.getchannel('A').load()
|
|
empty = [x for x in range(W) if not any(alpha[x, y] for y in range(H))]
|
|
cut = min(empty, key=lambda x: abs(x - W // 2))
|
|
for half, out in ((im.crop((0, 0, cut, H)), left_out), (im.crop((cut, 0, W, H)), right_out)):
|
|
box = half.getchannel('A').getbbox()
|
|
part = half.crop(box)
|
|
small = part.resize((round(part.width * scale), round(part.height * scale)), Image.LANCZOS)
|
|
small.save(out, optimize=True)
|
|
print(out, 'ritaglio', box, '→', small.size)
|