Python Script To Make Favicons
Inhaltsverzeichnis
Prompt
python script to create based on "eva-klein.png" a set of favicons and a text file with the html for the website
Result
Was hat das früher gedauert. Heute braucht es nur einen Prompt und es geht.
from PIL import Image
import os
# Load image
image_path = "eva-klein.png"
image = Image.open(image_path)
# Define favicon sizes
favicon_sizes = [(16, 16), (32, 32), (48, 48), (64, 64)]
# Create favicons
favicons_folder = "favicons"
if not os.path.exists(favicons_folder):
os.makedirs(favicons_folder)
for size in favicon_sizes:
favicon = image.resize(size).convert("RGBA")
favicon.save(os.path.join(favicons_folder, f"favicon-{size[0]}x{size[1]}.png"))
# Create HTML code for favicons
html_code = "<!-- Favicons -->\n"
for size in favicon_sizes:
html_code += f'<link rel="icon" type="image/png" sizes="{size[0]}x{size[1]}" href="favicons/favicon-{size[0]}x{size[1]}.png">\n'
# Write HTML code to file
html_file = "favicons.html"
with open(html_file, "w") as f:
f.write(html_code)
print(f"HTML code for favicons saved to '{html_file}'")