diff --git a/static/img/favicon-gen.py b/static/img/favicon-gen.py index ba6faeb..043abf8 100644 --- a/static/img/favicon-gen.py +++ b/static/img/favicon-gen.py @@ -1,25 +1,54 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- +""" +Generate favicon.ico from SVG using cairosvg and PIL +""" import os +import io +from cairosvg import svg2png from PIL import Image -import cairosvg -# Pfad zum SVG-Favicon -svg_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'favicon.svg') -# Ausgabepfad für das PNG -png_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'favicon.png') -# Ausgabepfad für das ICO -ico_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'favicon.ico') +# Verzeichnis dieses Skripts +CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) -# SVG zu PNG konvertieren -cairosvg.svg2png(url=svg_path, write_to=png_path, output_width=512, output_height=512) +def svg_to_ico(svg_path, ico_path, sizes=[16, 32, 48, 64, 128, 256]): + """Convert SVG to multi-size ICO file""" + img_io = io.BytesIO() + + # Höchste Auflösung für Zwischenspeicherung + max_size = max(sizes) + + # SVG in PNG konvertieren + with open(svg_path, 'rb') as svg_file: + svg_data = svg_file.read() + svg2png(bytestring=svg_data, write_to=img_io, output_width=max_size, output_height=max_size) + + # PNG in verschiedene Größen konvertieren + img = Image.open(img_io) + + # Alle Größen für das ICO-Format vorbereiten + img_list = [] + for size in sizes: + resized_img = img.resize((size, size), Image.LANCZOS) + img_list.append(resized_img) + + # ICO-Datei speichern + img_list[0].save( + ico_path, + format='ICO', + sizes=[(img.width, img.height) for img in img_list], + append_images=img_list[1:] + ) + print(f"Favicon {ico_path} wurde erstellt!") -# PNG zu ICO konvertieren -img = Image.open(png_path) -img.save(ico_path, sizes=[(16, 16), (32, 32), (48, 48), (64, 64), (128, 128)]) +# Ursprüngliches Favicon konvertieren +svg_to_ico( + os.path.join(CURRENT_DIR, 'favicon.svg'), + os.path.join(CURRENT_DIR, 'favicon.ico') +) -print(f"Favicon erfolgreich erstellt: {ico_path}") - -# Optional: PNG-Datei löschen, wenn nur ICO benötigt wird -# os.remove(png_path) \ No newline at end of file +# Neues Neuron-Favicon konvertieren +svg_to_ico( + os.path.join(CURRENT_DIR, 'neuron-favicon.svg'), + os.path.join(CURRENT_DIR, 'neuron-favicon.ico') +) \ No newline at end of file diff --git a/static/img/neuron-favicon.svg b/static/img/neuron-favicon.svg new file mode 100644 index 0000000..c2976f7 --- /dev/null +++ b/static/img/neuron-favicon.svg @@ -0,0 +1,76 @@ + \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 9c93042..3947d83 100644 --- a/templates/base.html +++ b/templates/base.html @@ -6,8 +6,8 @@