"""Zoom crops of the user's blueprint with pixel rulers (sheet pixel coordinates), for reading by eye.""" import sys from PIL import Image, ImageDraw import os SRC = os.environ.get('ZSRC', 'reference/user_blueprint.png') def zoom(name, x0, y0, x1, y1, k=3, step=10): im = Image.open(SRC).crop((x0, y0, x1, y1)).resize(((x1-x0)*k, (y1-y0)*k), Image.LANCZOS) d = ImageDraw.Draw(im) for x in range((x0//step+1)*step, x1, step): X = (x-x0)*k; big = x % 50 == 0 d.line([(X, 0), (X, 12 if big else 5)], fill=(255,255,0) if big else (200,200,0)) if big: d.text((X+2, 12), str(x), fill=(255,255,0)) for y in range((y0//step+1)*step, y1, step): Y = (y-y0)*k; big = y % 50 == 0 d.line([(0, Y), (12 if big else 5, Y)], fill=(255,255,0) if big else (200,200,0)) if big: d.text((14, Y+2), str(y), fill=(255,255,0)) im.save(f'reference/z{k}_{name}.png') if __name__ == '__main__': a = sys.argv[1:] zoom(a[0], *map(int, a[1:5]), k=int(a[5]) if len(a) > 5 else 3)