-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_red_d2g_icon.py
More file actions
111 lines (88 loc) · 3.71 KB
/
Copy pathcreate_red_d2g_icon.py
File metadata and controls
111 lines (88 loc) · 3.71 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
from PIL import Image, ImageDraw, ImageFont
import os
ascii_art = r"""
██████████ ████████████ ██████████
████ ████ ████ ████ ████
████ ████ ████ ████
████ ████ ████████████ ████ ██████
████ ████ ████ ████ ████
████ ████ ████ ████ ████
████ ████ ████████████ ████ ████
██████████ ████████████ ██████████
"""
def create_icon():
print("Generating D2G Red Icon...")
# Configuration
img_size = 1024 # Work with a larger canvas for better quality
padding = 50
target_color = (255, 0, 0, 255) # Red
bg_color = (0, 0, 0, 0) # Transparent
# Create image
img = Image.new('RGBA', (img_size, img_size), color=bg_color)
draw = ImageDraw.Draw(img)
# Determine Max Font Size that fits
font_size = 10
font_path = "consola.ttf" # Windows standard
# Find optimal font size
lines = ascii_art.strip().split('\n')
max_line_len = max(len(line) for line in lines)
for size in range(10, 200, 2):
try:
font = ImageFont.truetype(font_path, size)
except OSError:
# Fallback for non-windows or if font missing
font = ImageFont.load_default()
break
# Check width
max_w = 0
total_h = 0
# Get line height
bbox_sample = draw.textbbox((0,0), "█", font=font)
line_height = bbox_sample[3] - bbox_sample[1]
# Add a little spacing
line_height = int(line_height * 1.0)
# Calculate total dimensions
for line in lines:
bbox = draw.textbbox((0,0), line, font=font)
w = bbox[2] - bbox[0]
max_w = max(max_w, w)
total_h = len(lines) * line_height
if max_w > (img_size - 2*padding) or total_h > (img_size - 2*padding):
font_size = size - 2
break
font_size = size
print(f"Selected Font Size: {font_size}")
try:
font = ImageFont.truetype(font_path, font_size)
except:
font = ImageFont.load_default()
# Recalculate positions with final font
bbox_sample = draw.textbbox((0,0), "█", font=font)
line_height = bbox_sample[3] - bbox_sample[1] # standard height
# Calculate exact bounding box of the whole block to center it
lines_metrics = []
block_width = 0
block_height = 0
for line in lines:
bbox = draw.textbbox((0,0), line, font=font)
w = bbox[2] - bbox[0]
block_width = max(block_width, w)
block_height = len(lines) * line_height
start_x = (img_size - block_width) // 2
start_y = (img_size - block_height) // 2
# Draw
y = start_y
for line in lines:
draw.text((start_x, y), line, fill=target_color, font=font)
y += line_height
# Save PNG
output_png = 'd:/Coding/TruTopsDWGtoGEO/d2g_icon_red.png'
img.save(output_png)
print(f"Saved PNG to {output_png}")
# Save ICO
output_ico = 'd:/Coding/TruTopsDWGtoGEO/d2g_icon_red.ico'
sizes = [(256, 256), (128, 128), (64, 64), (48, 48), (32, 32), (16, 16)]
img.save(output_ico, format='ICO', sizes=sizes)
print(f"Saved ICO to {output_ico}")
if __name__ == "__main__":
create_icon()