salvagedb_web/generate_icons.py

31 lines
1.1 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.

from PIL import Image
import os
def generate_icons():
# Создаем директорию если её нет
if not os.path.exists('static/icons'):
os.makedirs('static/icons')
# Открываем исходное изображение
source = Image.open('static/Logo2.png')
# Размеры иконок
sizes = [72, 96, 128, 144, 152, 192, 384, 512]
# Генерируем иконки каждого размера
for size in sizes:
# Создаем новое изображение с белым фоном
icon = Image.new('RGBA', (size, size), (255, 255, 255, 0))
# Изменяем размер исходного изображения
resized = source.resize((size, size), Image.Resampling.LANCZOS)
# Вставляем в центр
icon.paste(resized, (0, 0))
# Сохраняем
icon.save(f'static/icons/icon-{size}x{size}.png', 'PNG')
print(f'Создана иконка {size}x{size}')
if __name__ == '__main__':
generate_icons()