Skip to content

Commit 728b0a6

Browse files
committed
Add automatic icon optimization to workflow
Automatically trims, resizes, and centers package icon to 512x512 with transparent background
1 parent 394e451 commit 728b0a6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

.github/workflows/nuget-publish.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@ jobs:
2222
- name: Checkout code
2323
uses: actions/checkout@v4
2424

25+
- name: Optimize package icon
26+
run: |
27+
python3 << 'EOF'
28+
from PIL import Image
29+
import os
30+
31+
icon_path = 'icon.png'
32+
if os.path.exists(icon_path):
33+
print(f"Processing {icon_path}...")
34+
img = Image.open(icon_path)
35+
36+
# Trim transparent borders
37+
bbox = img.getbbox()
38+
if bbox:
39+
img = img.crop(bbox)
40+
print(f"Trimmed to: {img.size}")
41+
42+
# Resize maintaining aspect ratio
43+
img.thumbnail((512, 512), Image.Resampling.LANCZOS)
44+
print(f"Resized to: {img.size}")
45+
46+
# Center on 512x512 canvas with transparent background
47+
new_img = Image.new('RGBA', (512, 512), (0, 0, 0, 0))
48+
offset = ((512 - img.width) // 2, (512 - img.height) // 2)
49+
new_img.paste(img, offset)
50+
51+
# Save optimized
52+
new_img.save(icon_path, 'PNG', optimize=True)
53+
print(f"Saved optimized icon: {os.path.getsize(icon_path)} bytes")
54+
else:
55+
print(f"Icon not found at {icon_path}, skipping optimization")
56+
EOF
57+
2558
- name: Setup .NET SDKs
2659
uses: actions/setup-dotnet@v4
2760
with:

0 commit comments

Comments
 (0)