Fabio Antonini commited on
Commit
1b801d3
·
1 Parent(s): 73f01ee

Add testamento and signature generation script with sample images

Browse files
data/samples/testamento_fittizio.docx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ef711a13e6e2f0c8d8ac364eef8540406a43a6df74f50f1aed0791c98b9b88a
3
+ size 26913
data/samples/testamento_writer00.png ADDED

Git LFS Details

  • SHA256: c1c5bee4ad0518e834a570df03bdf939a83eef7cfa5e7673c3743328ce2d92eb
  • Pointer size: 131 Bytes
  • Size of remote file: 880 kB
scripts/create_testamento_writer00.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Crea data/samples/testamento_writer00.png
3
+
4
+ Documento composto da campioni reali di grafia writer_00 (opzione A).
5
+ Corpo testo: campioni writer_00/sample_*.png impilati verticalmente.
6
+ Firma: CEDAR original_1_1.png (writer_00) + etichetta "Luca Rossi".
7
+ """
8
+
9
+ from pathlib import Path
10
+ from PIL import Image, ImageDraw, ImageFont
11
+
12
+ ROOT = Path(__file__).parent.parent
13
+ SAMPLES = ROOT / "data/samples/writer_00"
14
+ FIRMA = ROOT / "data/cedar/signatures/full_org/original_1_1.png"
15
+ OUT_IMG = ROOT / "data/samples/testamento_writer00.png"
16
+
17
+ # Campioni selezionati (indici diversi = frasi diverse)
18
+ SELECTED = [0, 4, 8, 12, 18, 25]
19
+
20
+ PAGE_W = 1800
21
+ MARGIN_X = 130
22
+ MARGIN_TOP = 100
23
+ GAP = 45 # spazio verticale tra campioni
24
+ SIG_GAP = 90 # spazio prima della firma
25
+ SIG_H = 170 # altezza target firma
26
+ MARGIN_BOT = 100
27
+
28
+
29
+ def load_sample(idx: int, target_w: int) -> Image.Image:
30
+ path = SAMPLES / f"sample_{idx:03d}.png"
31
+ img = Image.open(path).convert("L")
32
+ scale = target_w / img.width
33
+ new_h = int(img.height * scale)
34
+ img = img.resize((target_w, new_h), Image.LANCZOS)
35
+ rgb = img.convert("RGB")
36
+ # assicura sfondo bianco
37
+ return rgb
38
+
39
+
40
+ def main() -> None:
41
+ available = sorted(SAMPLES.glob("sample_*.png"))
42
+ max_idx = len(available) - 1
43
+ indices = [i for i in SELECTED if i <= max_idx]
44
+
45
+ text_w = PAGE_W - 2 * MARGIN_X
46
+ samples = [load_sample(i, text_w) for i in indices]
47
+
48
+ # Altezza canvas
49
+ body_h = sum(s.height for s in samples) + GAP * (len(samples) - 1)
50
+ page_h = MARGIN_TOP + body_h + SIG_GAP + SIG_H + MARGIN_BOT
51
+
52
+ canvas = Image.new("RGB", (PAGE_W, page_h), (255, 255, 255))
53
+
54
+ # Incolla campioni
55
+ y = MARGIN_TOP
56
+ for samp in samples:
57
+ canvas.paste(samp, (MARGIN_X, y))
58
+ y += samp.height + GAP
59
+
60
+ # Firma CEDAR writer_1
61
+ sig = Image.open(FIRMA).convert("RGBA")
62
+ scale = SIG_H / sig.height
63
+ sig_w = int(sig.width * scale)
64
+ sig = sig.resize((sig_w, SIG_H), Image.LANCZOS)
65
+
66
+ sig_bg = Image.new("RGB", sig.size, (255, 255, 255))
67
+ sig_bg.paste(sig, mask=sig.split()[3])
68
+
69
+ sig_x = PAGE_W - sig_w - MARGIN_X
70
+ sig_y = y + SIG_GAP
71
+ canvas.paste(sig_bg, (sig_x, sig_y))
72
+
73
+ # Etichetta "Luca Rossi"
74
+ draw = ImageDraw.Draw(canvas)
75
+ try:
76
+ font = ImageFont.truetype("inkfree.ttf", size=46)
77
+ except (IOError, OSError):
78
+ try:
79
+ font = ImageFont.truetype("C:/Windows/Fonts/inkfree.ttf", size=46)
80
+ except (IOError, OSError):
81
+ font = ImageFont.load_default()
82
+
83
+ lx = sig_x + sig_w // 2
84
+ ly = sig_y + SIG_H + 8
85
+ draw.text((lx, ly), "Luca Rossi", fill=(50, 50, 50), font=font, anchor="mt")
86
+
87
+ canvas.save(OUT_IMG, "PNG")
88
+ print(f"Creato: {OUT_IMG} ({PAGE_W}x{page_h}px)")
89
+
90
+
91
+ if __name__ == "__main__":
92
+ main()