"""Zoomed crops of the user's picture with pixel rulers, for reading parts and edges. python tg_zoom.py NAME x0 y0 x1 y1 [scale] -> reference/z_NAME.png Ticks every 10 px, labels every 50 px, in the picture's own pixel coordinates. """ import sys from pathlib import Path from PIL import Image, ImageDraw ROOT = Path(__file__).resolve().parents[1] SRC = ROOT / "reference" / "user_picture.jpg" def zoom(name, x0, y0, x1, y1, s=3): im = Image.open(SRC).convert("RGB").crop((x0, y0, x1, y1)) im = im.resize(((x1 - x0) * s, (y1 - y0) * s), Image.LANCZOS) pad = 28 out = Image.new("RGB", (im.width + pad, im.height + pad), (255, 255, 255)) out.paste(im, (pad, pad)) d = ImageDraw.Draw(out) for x in range((x0 // 10) * 10, x1 + 1, 10): if x < x0: continue px = pad + (x - x0) * s big = x % 50 == 0 d.line([(px, pad - (10 if big else 4)), (px, pad)], fill=(0, 0, 0)) if big: d.text((px + 2, 2), str(x), fill=(200, 0, 0)) d.line([(px, pad), (px, out.height)], fill=(255, 0, 255)) for y in range((y0 // 10) * 10, y1 + 1, 10): if y < y0: continue py = pad + (y - y0) * s big = y % 50 == 0 d.line([(pad - (10 if big else 4), py), (pad, py)], fill=(0, 0, 0)) if big: d.text((1, py + 2), str(y), fill=(200, 0, 0)) d.line([(pad, py), (out.width, py)], fill=(255, 0, 255)) dst = ROOT / "reference" / f"z_{name}.png" out.save(dst) print(dst) if __name__ == "__main__": a = sys.argv[1:] zoom(a[0], *map(int, a[1:5]), *(map(int, a[5:6]) if len(a) > 5 else []))