English: tools renamed and translated (same numbers as before), options and printed names in English; the guide translated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-11-16 12:40:03 +01:00
1 parent 67c88625c5
commit f28bd19e04
25 files changed
+2764 -2762

No files matched your search

+43 -43
View File
@@ -1,12 +1,12 @@
"""GIF des images de la caméra sur une plage, pour joindre à une réponse au client.
"""GIF of the camera images over a range, to attach to a reply to the client.
Usage : .venv/bin/python tools/scripts/gif.py data/LENZSPITZE/
--debut 2026-10-26T18:00Z --fin 2026-10-27T08:00Z [--largeur 720] [--duree 700] [--max 150] [--zone X,Y,L,H] [--sortie DOSSIER]
Prend les images du dossier dont l'heure (nom du fichier, UTC) est entre --debut et --fin inclus, dans l'ordre, les
recadre au besoin sur --zone (pixels de l'image d'origine : coin haut gauche, largeur, hauteur), les met à --largeur px,
écrit la date et l'heure UTC en bas à droite de chacune et les ramène à 64 teintes sans tramage
(le bruit des JPEG gonfle un GIF : ~3 Mo pour une nuit d'images horaires à 720 px). Au-delà de --max images, en garde
--max à intervalle régulier. Imprime l'heure de chaque image retenue, puis le chemin du GIF et sa taille.
Usage: .venv/bin/python tools/scripts/gif.py data/LENZSPITZE/
--start 2026-10-26T18:00Z --end 2026-10-27T08:00Z [--width 720] [--duration 700] [--max 150] [--zone X,Y,W,H] [--out FOLDER]
Takes the images of the folder whose time (file name, UTC) is between --start and --end inclusive, in order,
crops them if needed to --zone (pixels of the original image: top left corner, width, height), scales them to --width px,
writes the UTC date and time at the bottom right of each one and reduces them to 64 colours without dithering
(JPEG noise inflates a GIF: ~3 MB for a night of hourly images at 720 px). Beyond --max images, keeps
--max at regular intervals. Prints the time of each image kept, then the path of the GIF and its size.
"""
import argparse
import os
@@ -14,55 +14,55 @@ import sys
from PIL import Image, ImageDraw, ImageFont
from donnees import heure_image, instant, iso, trouver
from data import find_files, image_time, iso, parse_time
def main():
a = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
a.add_argument("dossier")
a.add_argument("--debut", required=True, help="première heure (UTC)")
a.add_argument("--fin", required=True, help="dernière heure (UTC), incluse")
a.add_argument("--largeur", type=int, default=720, help="largeur du GIF en pixels (défaut 720)")
a.add_argument("--duree", type=int, default=700, help="durée de chaque image en ms (défaut 700)")
a.add_argument("--max", type=int, default=150, help="nombre maximal d'images (défaut 150)")
a.add_argument("--zone", help="X,Y,L,H : recadrage en pixels de l'image d'origine (défaut : image entière)")
a.add_argument("--sortie", default=os.path.join("out", "diagnostic"), help="dossier du GIF")
a.add_argument("folder")
a.add_argument("--start", required=True, help="first time (UTC)")
a.add_argument("--end", required=True, help="last time (UTC), included")
a.add_argument("--width", type=int, default=720, help="width of the GIF in pixels (default 720)")
a.add_argument("--duration", type=int, default=700, help="duration of each image in ms (default 700)")
a.add_argument("--max", type=int, default=150, help="maximum number of images (default 150)")
a.add_argument("--zone", help="X,Y,W,H: crop in pixels of the original image (default: whole image)")
a.add_argument("--out", default=os.path.join("out", "diagnostic"), help="folder of the GIF")
o = a.parse_args()
debut, fin = instant(o.debut), instant(o.fin)
toutes = sorted((h, p) for p in trouver(o.dossier)["images"] if (h := heure_image(p)))
choisies = [(h, p) for h, p in toutes if debut <= h <= fin]
if not choisies:
dispo = f" (images du {iso(toutes[0][0])} au {iso(toutes[-1][0])})" if toutes else ""
sys.exit(f"Aucune image entre {iso(debut)} et {iso(fin)} dans {o.dossier}{dispo}.")
n = len(choisies)
start, end = parse_time(o.start), parse_time(o.end)
every = sorted((h, p) for p in find_files(o.folder)["images"] if (h := image_time(p)))
chosen = [(h, p) for h, p in every if start <= h <= end]
if not chosen:
available = f" (images from {iso(every[0][0])} to {iso(every[-1][0])})" if every else ""
sys.exit(f"No image between {iso(start)} and {iso(end)} in {o.folder}{available}.")
n = len(chosen)
if n > o.max:
choisies = [choisies[round(i * (n - 1) / (o.max - 1))] for i in range(o.max)]
print(f"{o.max} images sur {n} gardées")
chosen = [chosen[round(i * (n - 1) / (o.max - 1))] for i in range(o.max)]
print(f"{o.max} of {n} images kept")
vues = []
for h, p in choisies:
frames = []
for h, p in chosen:
im = Image.open(p).convert("RGB")
if o.zone:
x, y, l, h_ = map(int, o.zone.split(","))
im = im.crop((x, y, x + l, y + h_))
im = im.resize((o.largeur, round(im.height * o.largeur / im.width)), Image.LANCZOS)
x, y, w, h_ = map(int, o.zone.split(","))
im = im.crop((x, y, x + w, y + h_))
im = im.resize((o.width, round(im.height * o.width / im.width)), Image.LANCZOS)
d = ImageDraw.Draw(im)
texte = h.strftime("%Y-%m-%d %H:%M UTC")
police = ImageFont.load_default(size=max(12, o.largeur // 45))
g, haut, dr, bas = d.textbbox((0, 0), texte, font=police)
x, y, marge = im.width - (dr - g) - 10, im.height - (bas - haut) - 10, 4
d.rectangle((x - marge, y - marge, x + dr - g + marge, y + bas - haut + marge), fill="black")
d.text((x - g, y - haut), texte, fill="white", font=police)
vues.append(im.quantize(64, dither=Image.Dither.NONE))
text = h.strftime("%Y-%m-%d %H:%M UTC")
font = ImageFont.load_default(size=max(12, o.width // 45))
left, top, right, bottom = d.textbbox((0, 0), text, font=font)
x, y, margin = im.width - (right - left) - 10, im.height - (bottom - top) - 10, 4
d.rectangle((x - margin, y - margin, x + right - left + margin, y + bottom - top + margin), fill="black")
d.text((x - left, y - top), text, fill="white", font=font)
frames.append(im.quantize(64, dither=Image.Dither.NONE))
print(iso(h))
os.makedirs(o.sortie, exist_ok=True)
nom = f"images_{choisies[0][0]:%Y%m%dT%H%MZ}_{choisies[-1][0]:%Y%m%dT%H%MZ}.gif"
chemin = os.path.join(o.sortie, nom)
vues[0].save(chemin, save_all=True, append_images=vues[1:], duration=o.duree, loop=0, optimize=True)
print(f"GIF : {chemin} ({os.path.getsize(chemin) / 1e6:.1f} Mo, {len(vues)} images)")
os.makedirs(o.out, exist_ok=True)
name = f"images_{chosen[0][0]:%Y%m%dT%H%MZ}_{chosen[-1][0]:%Y%m%dT%H%MZ}.gif"
path = os.path.join(o.out, name)
frames[0].save(path, save_all=True, append_images=frames[1:], duration=o.duration, loop=0, optimize=True)
print(f"GIF: {path} ({os.path.getsize(path) / 1e6:.1f} MB, {len(frames)} images)")
if __name__ == "__main__":