Created
July 17, 2020 11:13
-
-
Save graphoarty/6123c968de24beb8306c6dc002997808 to your computer and use it in GitHub Desktop.
Python 3.7 Script for Generating Mac ICNS File from PNG Logo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import os | |
logo_path = '/path/to/logo.png' | |
resize_sizes = [ | |
{ | |
"file_name": "icon_16x16.png", | |
"size": (16, 16) | |
}, | |
{ | |
"file_name": "icon_16x16@2x.png", | |
"size": (32, 32) | |
}, | |
{ | |
"file_name": "icon_32x32.png", | |
"size": (32, 32) | |
}, | |
{ | |
"file_name": "icon_32x32@2x.png", | |
"size": (64, 64) | |
}, | |
{ | |
"file_name": "icon_64x64.png", | |
"size": (64, 64) | |
}, | |
{ | |
"file_name": "icon_64x64@2x.png", | |
"size": (128, 128) | |
}, | |
{ | |
"file_name": "icon_128x128.png", | |
"size": (128, 128) | |
}, | |
{ | |
"file_name": "icon_128x128@2x.png", | |
"size": (256, 256) | |
}, | |
{ | |
"file_name": "icon_256x256.png", | |
"size": (256, 256) | |
}, | |
{ | |
"file_name": "icon_256x256@2x.png", | |
"size": (512, 512) | |
}, | |
{ | |
"file_name": "icon_512x512.png", | |
"size": (512, 512) | |
}, | |
{ | |
"file_name": "icon_512x512@2x.png", | |
"size": (1024, 1024) | |
} | |
] | |
for item in resize_sizes: | |
print('Processing: ' + item['file_name']) | |
image = Image.open(logo_path) | |
image = image.resize(item['size'], Image.ANTIALIAS) | |
if not os.path.exists(os.path.join(os.path.dirname(logo_path), 'icon.iconset')): | |
os.mkdir(os.path.join(os.path.dirname(logo_path), 'icon.iconset')) | |
image = image.save(os.path.join(os.path.join(os.path.dirname(logo_path), 'icon.iconset'), item['file_name']), quality=100) | |
os.system(f"iconutil -c icns {os.path.join(os.path.dirname(logo_path), 'icon.iconset')} {os.path.join(os.path.dirname(logo_path), 'icon.icns')}") | |
os.system(f"open {os.path.dirname(logo_path)}") | |
print(f"Find ICNS File at {os.path.join(os.path.dirname(logo_path), 'icon.icns')}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment