21 lines
786 B
Python
21 lines
786 B
Python
"""Recadre la même zone de plusieurs images et les met côte à côte. Usage: crop.py X0,Y0,X1,Y1 sortie.png HHMM_ids..."""
|
|||
|
|
import sys, glob
|
||
|
|
from PIL import Image, ImageDraw
|
||
|
|
box = tuple(int(v) for v in sys.argv[1].split(","))
|
||
|
|
out = sys.argv[2]
|
||
|
|
tiles = []
|
||
|
|
for tag in sys.argv[3:]:
|
||
|
|
f = glob.glob(f"data/BREITHORN/images/{tag}*.jpg")[0]
|
||
|
|
im = Image.open(f).convert("L").crop(box)
|
||
|
|
im = im.point(lambda p: min(255, p * 3)) # même étirement pour toutes
|
||
|
|
d = ImageDraw.Draw(im)
|
||
|
|
d.text((5, 5), tag, fill=255)
|
||
|
|
tiles.append(im)
|
||
|
|
w, h = tiles[0].size
|
||
|
|
cols = min(4, len(tiles))
|
||
|
|
rows = (len(tiles) + cols - 1) // cols
|
||
|
|
sheet = Image.new("L", (w * cols, h * rows))
|
||
|
|
for i, t in enumerate(tiles):
|
||
|
|
sheet.paste(t, ((i % cols) * w, (i // cols) * h))
|
||
|
|
sheet.save(out)
|
||
|
|
print(out)
|