63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ASSETS = ROOT / "assets"
|
|
SCALE = 4
|
|
SIZE = 256
|
|
CANVAS = SIZE * SCALE
|
|
|
|
|
|
def scaled_points(points):
|
|
return [(x * SCALE, y * SCALE) for x, y in points]
|
|
|
|
|
|
mask = Image.new("L", (CANVAS, CANVAS), 0)
|
|
mask_draw = ImageDraw.Draw(mask)
|
|
mask_draw.rounded_rectangle(
|
|
(8 * SCALE, 8 * SCALE, 248 * SCALE, 248 * SCALE),
|
|
radius=54 * SCALE,
|
|
fill=255,
|
|
)
|
|
|
|
background = Image.new("RGBA", (CANVAS, CANVAS), (0, 0, 0, 0))
|
|
pixels = background.load()
|
|
for y in range(CANVAS):
|
|
ratio = y / max(1, CANVAS - 1)
|
|
red = round(59 + (29 - 59) * ratio)
|
|
green = round(130 + (78 - 130) * ratio)
|
|
blue = round(246 + (216 - 246) * ratio)
|
|
for x in range(CANVAS):
|
|
pixels[x, y] = (red, green, blue, mask.getpixel((x, y)))
|
|
|
|
draw = ImageDraw.Draw(background, "RGBA")
|
|
highlight = Image.new("RGBA", (CANVAS, CANVAS), (0, 0, 0, 0))
|
|
highlight_draw = ImageDraw.Draw(highlight, "RGBA")
|
|
highlight_draw.ellipse(
|
|
(-60 * SCALE, -110 * SCALE, 250 * SCALE, 150 * SCALE),
|
|
fill=(255, 255, 255, 22),
|
|
)
|
|
background.alpha_composite(highlight)
|
|
|
|
w_shape = [
|
|
(44, 66), (78, 66), (105, 157), (128, 98),
|
|
(129, 98), (152, 157), (179, 66), (212, 66),
|
|
(174, 192), (139, 192), (128, 161), (116, 192),
|
|
(82, 192),
|
|
]
|
|
shadow_shape = [(x, y + 4) for x, y in w_shape]
|
|
draw.polygon(scaled_points(shadow_shape), fill=(10, 35, 90, 45))
|
|
draw.polygon(scaled_points(w_shape), fill=(255, 255, 255, 255))
|
|
|
|
icon = background.resize((SIZE, SIZE), Image.Resampling.LANCZOS)
|
|
ASSETS.mkdir(parents=True, exist_ok=True)
|
|
icon.save(ASSETS / "WindowsToolbox.png", "PNG", optimize=True)
|
|
icon.save(
|
|
ASSETS / "WindowsToolbox.ico",
|
|
"ICO",
|
|
sizes=[(16, 16), (20, 20), (24, 24), (32, 32), (40, 40), (48, 48), (64, 64), (128, 128), (256, 256)],
|
|
)
|
|
print(ASSETS / "WindowsToolbox.ico")
|