Files
neon-bar86.ru/site/scripts/make-favicon.py
T
2026-10-11 22:24:54 +05:00

52 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Генератор favicon-набора сайта НЕОН: python scripts/make-favicon.py
# Запускается вручную (нужен Pillow: pip install pillow). Рисует фирменный
# логотип «Н» и складывает файлы в public/ — Vite копирует их в корень
# сборки, nginx отдаёт /favicon.ico поисковикам (Яндекс/Google забирают
# иконку именно с адреса /favicon.ico, data-URI из <head> они не читают).
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parent.parent
OUT = ROOT / "public"
BG = (10, 10, 15, 255) # #0A0A0F
FG = (0, 240, 255, 255) # #00F0FF
FONT = r"C:\Windows\Fonts\ariblk.ttf" # Arial Black — как в SVG-логотипе
RADIUS_RATIO = 14 / 64 # скругление углов из SVG (rx=14 при 64)
def draw_badge(size: int, rounded: bool) -> Image.Image:
img = Image.new("RGBA", (size, size), (0, 0, 0, 0))
d = ImageDraw.Draw(img)
if rounded:
d.rounded_rectangle([0, 0, size - 1, size - 1],
radius=round(size * RADIUS_RATIO), fill=BG)
else:
# apple-touch-icon: без прозрачных углов — iOS сам скругляет маской
d.rectangle([0, 0, size, size], fill=BG)
font = ImageFont.truetype(FONT, round(size * 34 / 64))
d.text((size / 2, size * 0.53), "Н", font=font, fill=FG, anchor="mm")
return img
OUT.mkdir(exist_ok=True)
# вектор — браузеры с поддержкой SVG-иконок берут его, файл не зависит от шрифтов
(OUT / "favicon.svg").write_text(
"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'>"
"<rect width='64' height='64' rx='14' fill='#0A0A0F'/>"
"<text x='32' y='45' font-family='Arial Black, Arial' font-size='34' "
"font-weight='900' text-anchor='middle' fill='#00F0FF'>Н</text></svg>",
encoding="utf-8",
)
master = draw_badge(512, rounded=True)
for px in (48, 32, 16):
master.resize((px, px), Image.LANCZOS).save(OUT / f"favicon-{px}x{px}.png")
# favicon.ico: 16+32+48 в одном файле — его запрашивают поисковики напрямую
master.save(OUT / "favicon.ico", sizes=[(16, 16), (32, 32), (48, 48)])
draw_badge(180, rounded=False).save(OUT / "apple-touch-icon.png")
print("OK: favicon.ico, favicon.svg, favicon-16x16.png, favicon-32x32.png,",
"favicon-48x48.png, apple-touch-icon.png ->", OUT)