ratp: Improve icon readability

This commit is contained in:
nemunaire 2024-05-13 07:13:11 +02:00
parent 2b4968c566
commit 8c9417a50e

View File

@ -224,20 +224,41 @@ class IDFMAPI:
elif mode == "R" or mode == "rers": elif mode == "R" or mode == "rers":
icon_mode = "RER" icon_mode = "RER"
img_line = None
if mode != "buses": if mode != "buses":
if fill == "white":
img = Image.open(os.path.join(config.icons_dir, "ratp", "lignes", icon_mode + "_" + line + "_NB" + state + "_RVB.png")) img = Image.open(os.path.join(config.icons_dir, "ratp", "lignes", icon_mode + "_" + line + "_NB" + state + "_RVB.png"))
return img.resize((int(size), int(img.height * size / img.width))) return img.resize((int(size), int(img.height * size / img.width)))
else:
img_line = Image.open(os.path.join(config.icons_dir, "ratp", "lignes", icon_mode + "_" + line + "_NB_RVB.png"))
img = Image.new(img_line.mode, (img_line.width, int(img_line.height * 1.4)))
img.paste(img_line, (0,0))
else:
width = int(size * 1.38) if mode == "buses" or mode == "tramways" else size width = int(size * 1.38)
image = Image.new('RGBA', (width, size), '#fff0') img = Image.new('RGBA', (width, width), '#fff0')
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(img)
fnt_icon = ImageFont.truetype(os.path.join(config.fonts_dir, IDFMAPI.fnt_RB_path), size-3) fnt_icon = ImageFont.truetype(os.path.join(config.fonts_dir, IDFMAPI.fnt_RB_path), size-3)
draw.rectangle((0, 0, width, size), fill=fill) draw.rectangle((0, 0, width, size), fill="#222")
draw.text((int(width / 2), int(size / 2)), line, fill="white" if (fill == "black" and mode == "tramways") or (fill != "white" and mode != "tramways") or (fill == "white" and mode == "tramways") else "black", anchor="mm", font=fnt_icon) draw.text((int(width / 2), int(size / 2)), line, fill="white", anchor="mm", font=fnt_icon)
return image if state != "":
if state.endswith("petit"):
coeff = 2.5
elif state.endswith("moyen"):
coeff = 2
else:
coeff = 1.5
img_perturb = Image.open(os.path.join(config.icons_dir, "ratp", "Perturbation_travaux_NB_RVB.png" if state.startswith("_travaux") else "Perturbation_trafic_NB_RVB.png"))
img_perturb = img_perturb.resize((int(img.width / coeff), int(img_perturb.height * img.width / (coeff * img_perturb.width))))
if img_line is not None:
img.paste(img_perturb, (img.width-img_perturb.width,img_line.height-int(img_perturb.height/coeff)))
else:
img.paste(img_perturb, (img.width-img_perturb.width,img.height-img_perturb.height))
return img.resize((int(size), int(img.height * size / img.width)))