-
Notifications
You must be signed in to change notification settings - Fork 925
Expand file tree
/
Copy pathgenerate_rounded_icons.py
More file actions
executable file
·107 lines (80 loc) · 3.33 KB
/
Copy pathgenerate_rounded_icons.py
File metadata and controls
executable file
·107 lines (80 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env -S uv run
# /// script
# dependencies = [
# "pillow",
# ]
# ///
import os
import subprocess
from PIL import Image, ImageDraw
SOURCE_ICON = "/Users/dex/go/src/github.com/metalytics-dev/metalytics/app/public/humanlayer-dark.png"
ICON_DIR = "/Users/dex/wt/humanlayer/eng-1689/humanlayer-wui/src-tauri/icons"
def create_rounded_corners_mask(size, radius):
"""Create a mask for rounded corners"""
mask = Image.new("L", (size, size), 0)
draw = ImageDraw.Draw(mask)
# Draw a rounded rectangle
draw.rounded_rectangle([(0, 0), (size - 1, size - 1)], radius=radius, fill=255)
return mask
def create_rounded_icon(source_path, output_path, size):
"""Create a rounded corner icon at the specified size"""
# Open and resize the source image
img = Image.open(source_path)
img = img.convert("RGBA")
img = img.resize((size, size), Image.Resampling.LANCZOS)
# Create a rounded corners mask
radius = size // 5 # 20% corner radius
mask = create_rounded_corners_mask(size, radius)
# Create output image with transparent background
output = Image.new("RGBA", (size, size), (0, 0, 0, 0))
output.paste(img, (0, 0))
# Apply the mask to the alpha channel
output.putalpha(mask)
# Save the result
output.save(output_path, "PNG")
print(f"Created: {output_path} ({size}x{size})")
def main():
print("Generating rounded corner icons...")
# Ensure icon directory exists
os.makedirs(ICON_DIR, exist_ok=True)
# Generate main icons
create_rounded_icon(SOURCE_ICON, f"{ICON_DIR}/icon.png", 512)
create_rounded_icon(SOURCE_ICON, f"{ICON_DIR}/32x32.png", 32)
create_rounded_icon(SOURCE_ICON, f"{ICON_DIR}/128x128.png", 128)
create_rounded_icon(SOURCE_ICON, f"{ICON_DIR}/[email protected]", 256)
# Generate Windows Store icons
for size in [30, 44, 71, 89, 107, 142, 150, 284, 310]:
create_rounded_icon(SOURCE_ICON, f"{ICON_DIR}/Square{size}x{size}Logo.png", size)
create_rounded_icon(SOURCE_ICON, f"{ICON_DIR}/StoreLogo.png", 50)
# Generate iconset for macOS
print("\nCreating macOS iconset...")
iconset_dir = "/tmp/icon.iconset"
os.makedirs(iconset_dir, exist_ok=True)
# Standard macOS icon sizes
icon_sizes = [
(16, "icon_16x16.png"),
(32, "[email protected]"),
(32, "icon_32x32.png"),
(64, "[email protected]"),
(128, "icon_128x128.png"),
(256, "[email protected]"),
(256, "icon_256x256.png"),
(512, "[email protected]"),
(512, "icon_512x512.png"),
(512, "[email protected]"), # Will copy from icon.png
]
for size, filename in icon_sizes:
if filename == "[email protected]":
# Just copy the already generated icon
subprocess.run(["cp", f"{ICON_DIR}/icon.png", f"{iconset_dir}/{filename}"])
else:
create_rounded_icon(SOURCE_ICON, f"{iconset_dir}/{filename}", size)
# Convert to .icns
print("\nConverting to .icns format...")
subprocess.run(["iconutil", "-c", "icns", iconset_dir, "-o", f"{ICON_DIR}/icon.icns"])
# Cleanup
subprocess.run(["rm", "-rf", iconset_dir])
print("\nDone! All icons have been generated with rounded corners.")
print("Note: Windows .ico file kept as-is (Windows doesn't typically use rounded corners)")
if __name__ == "__main__":
main()