File size: 1,254 Bytes
b15c8ad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """Write assets/samples/{bill,scam}.png — the one-tap gr.Examples letters.
Run from the repo root: .venv\\Scripts\\python.exe scripts\\make_samples.py
The PNGs are committed; this script only re-runs when the letters change.
"""
from __future__ import annotations
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src"))
from PIL import Image # noqa: E402
from guardian.samples import NORMAL_BILL, SCAM_LETTER, render_letter # noqa: E402
def photographed(page, angle: float):
"""Faint paper-grey table + slight rotation, like a casual phone photo."""
rotated = page.rotate(angle, expand=True, fillcolor="#b9b4ab", resample=Image.BICUBIC)
table = Image.new("RGB", (rotated.width + 60, rotated.height + 60), "#b9b4ab")
table.paste(rotated, (30, 30))
return table
def main() -> None:
out_dir = os.path.join("assets", "samples")
os.makedirs(out_dir, exist_ok=True)
photographed(render_letter(NORMAL_BILL), 1.4).save(os.path.join(out_dir, "bill.png"))
photographed(render_letter(SCAM_LETTER), -1.2).save(os.path.join(out_dir, "scam.png"))
print(f"wrote {out_dir}\\bill.png and {out_dir}\\scam.png")
if __name__ == "__main__":
main()
|