"""Ruler crops of the reference picture: python zoom.py name u0 v0 u1 v1 scale [step] Writes reference/z_.png, the crop scaled up with a grid every picture px (labels in picture px).""" import sys from PIL import Image, ImageDraw name, u0, v0, u1, v1, sc = sys.argv[1], *map(int, sys.argv[2:7]) step = int(sys.argv[7]) if len(sys.argv) > 7 else 20 im = Image.open("../reference/ref_user.jpg").convert("RGB").crop((u0, v0, u1, v1)) im = im.resize((im.width * sc, im.height * sc), Image.LANCZOS) d = ImageDraw.Draw(im) for u in range((u0 // step + 1) * step, u1, step): x = (u - u0) * sc d.line([(x, 0), (x, im.height)], fill=(255, 0, 0) if u % (step * 5) == 0 else (120, 0, 0), width=1) d.text((x + 2, 2), str(u), fill=(255, 255, 0)) for v in range((v0 // step + 1) * step, v1, step): y = (v - v0) * sc d.line([(0, y), (im.width, y)], fill=(255, 0, 0) if v % (step * 5) == 0 else (120, 0, 0), width=1) d.text((2, y + 2), str(v), fill=(255, 255, 0)) im.save("../reference/z_%s.png" % name)