"""Crops of the reference with a pixel ruler, for measuring (python zoom.py x0 y0 x1 y1 scale step out.png).""" import sys, os from PIL import Image, ImageDraw, ImageFont HERE = os.path.dirname(os.path.abspath(__file__)) src = Image.open(os.path.join(os.path.dirname(HERE), "reference", "ref_user.jpg")).convert("RGB") x0, y0, x1, y1, s, step = map(int, sys.argv[1:7]) out = sys.argv[7] im = src.crop((x0, y0, x1, y1)).resize(((x1 - x0) * s, (y1 - y0) * s), Image.LANCZOS) d = ImageDraw.Draw(im) f = ImageFont.truetype(r"C:\Windows\Fonts\segoeui.ttf", 12) for x in range((x0 // step + 1) * step, x1, step): X = (x - x0) * s d.line([(X, 0), (X, im.height)], fill=(255, 0, 255) if x % (step * 5) == 0 else (255, 120, 255), width=1) d.text((X + 2, 2), str(x), fill=(255, 255, 0), font=f) for y in range((y0 // step + 1) * step, y1, step): Y = (y - y0) * s d.line([(0, Y), (im.width, Y)], fill=(255, 0, 255) if y % (step * 5) == 0 else (255, 120, 255), width=1) d.text((2, Y + 2), str(y), fill=(255, 255, 0), font=f) im.save(out)