Files
ProcessDock/tools/generate_icon.py

55 lines
1.7 KiB
Python
Raw Normal View History

from __future__ import annotations
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parents[1]
ASSETS = ROOT / "assets"
def load_font(size: int) -> ImageFont.FreeTypeFont | ImageFont.ImageFont:
candidates = (
Path(r"C:\Windows\Fonts\arialbd.ttf"),
Path(r"C:\Windows\Fonts\segoeuib.ttf"),
)
for candidate in candidates:
if candidate.exists():
return ImageFont.truetype(str(candidate), size)
return ImageFont.load_default()
def main() -> None:
ASSETS.mkdir(parents=True, exist_ok=True)
size = 1024
image = Image.new("RGBA", (size, size), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
# Soft shadow and the same violet visual language used by the GUI.
draw.rounded_rectangle((76, 84, 948, 956), radius=220, fill=(28, 34, 67, 52))
draw.rounded_rectangle((52, 52, 924, 924), radius=220, fill=(91, 91, 214, 255))
draw.rounded_rectangle((82, 82, 894, 894), radius=190, outline=(130, 130, 235, 255), width=10)
font = load_font(540)
label = "P"
bounds = draw.textbbox((0, 0), label, font=font)
width = bounds[2] - bounds[0]
height = bounds[3] - bounds[1]
position = ((size - width) / 2 - 14, (size - height) / 2 - bounds[1] - 4)
draw.text(position, label, font=font, fill=(255, 255, 255, 255))
png_path = ASSETS / "processdock.png"
ico_path = ASSETS / "processdock.ico"
image.save(png_path, optimize=True)
image.save(
ico_path,
format="ICO",
sizes=[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (128, 128), (256, 256)],
)
print(f"Generated {ico_path}")
if __name__ == "__main__":
main()