-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_icon.py
More file actions
153 lines (135 loc) · 3.74 KB
/
Copy pathgenerate_icon.py
File metadata and controls
153 lines (135 loc) · 3.74 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
"""
Generate app icon with GA text on blue background
"""
from PIL import Image, ImageDraw, ImageFont
import os
# Icon sizes needed for macOS
sizes = [16, 32, 64, 128, 256, 512, 1024]
# Blue background color
BLUE = (0, 122, 255) # iOS/macOS blue
WHITE = (255, 255, 255)
def create_icon(size):
"""Create an icon of the given size"""
# Create image with blue background
img = Image.new('RGB', (size, size), BLUE)
draw = ImageDraw.Draw(img)
# Calculate font size (roughly 50% of icon size)
font_size = int(size * 0.5)
# Try to use a system font, fallback to default if not available
try:
# Use San Francisco font on macOS
font = ImageFont.truetype('/System/Library/Fonts/Supplemental/Arial Bold.ttf', font_size)
except:
try:
font = ImageFont.truetype('/System/Library/Fonts/SFNS.ttf', font_size)
except:
# Fallback to default font
font = ImageFont.load_default()
# Get text bounding box for centering
text = "GA"
bbox = draw.textbbox((0, 0), text, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]
# Calculate position to center text
x = (size - text_width) // 2 - bbox[0]
y = (size - text_height) // 2 - bbox[1]
# Draw text
draw.text((x, y), text, fill=WHITE, font=font)
return img
def main():
# Output directory
iconset_dir = "GA Mac Dashboard/Assets.xcassets/AppIcon.appiconset"
print("Generating app icons...")
for size in sizes:
# 1x version
img = create_icon(size)
filename = f"icon_{size}x{size}.png"
filepath = os.path.join(iconset_dir, filename)
img.save(filepath, 'PNG')
print(f"Created {filename}")
# 2x version (double size)
if size <= 512: # Don't create 2x for 1024
img_2x = create_icon(size * 2)
filename_2x = f"icon_{size}x{size}@2x.png"
filepath_2x = os.path.join(iconset_dir, filename_2x)
img_2x.save(filepath_2x, 'PNG')
print(f"Created {filename_2x}")
print("\nApp icons generated successfully!")
print("Updating Contents.json...")
# Update Contents.json
contents_json = """{
"images" : [
{
"filename" : "icon_16x16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "icon_16x16@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "icon_32x32.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "icon_32x32@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "icon_128x128.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "icon_128x128@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "icon_256x256.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "icon_256x256@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "icon_512x512.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "icon_512x512@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}"""
contents_path = os.path.join(iconset_dir, "Contents.json")
with open(contents_path, 'w') as f:
f.write(contents_json)
print("Contents.json updated!")
print("\nDone! The app icon has been generated.")
if __name__ == "__main__":
main()