Skip to content

Instantly share code, notes, and snippets.

@febeling
Forked from ahmed-musallam/generate-icns.sh
Last active January 13, 2024 13:01
Show Gist options
  • Save febeling/d2131a91a09d9f313d03796c8a7470ae to your computer and use it in GitHub Desktop.
Save febeling/d2131a91a09d9f313d03796c8a7470ae to your computer and use it in GitHub Desktop.
A Shell script to generate .ico and .icns files (mac/windows app icons) from a single PNG
#!/bin/bash
# Required deps:
# imagemagick: https://imagemagick.org/script/download.php
# iconutil: https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
# name of your master icon, should be 1024x1024 or .svg
if [ -z "$PNG_MASTER" ]; then
# If not set, assign a default value
PNG_MASTER="icon-large.png"
fi
ICONSET_FOLDER="AppIcon.iconset"
sizes=(
16
32
128
256
512
)
# Generate renditions at the sizes in "sizes" above, put all in ICONSET_FOLDER
mkdir -p $ICONSET_FOLDER
for size in "${sizes[@]}"; do
icon="icon_${size}.png"
ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
echo Generating $ICONSET_FOLDER/$icon
convert $PNG_MASTER -quality 100 -resize ${size}x${size} $ICONSET_FOLDER/$icon
icon="icon_${size}x${size}@2x.png"
ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
echo Generating $ICONSET_FOLDER/$icon
hires=$((size * 2))
convert $PNG_MASTER -quality 100 -resize ${hires}x${hires} $ICONSET_FOLDER/$icon
done
# generate icon.icns for mac app (this only works on mac)
echo Generating icon.icns
iconutil -c icns $ICONSET_FOLDER -o icon.icns
# Generate .ico file for windows
ICON_FILES=""
for size in "${sizes[@]}"; do
ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}.png"
ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}x${size}@2x.png"
done
echo Generating icon.ico
convert $ICON_FILES icon.ico
# remove generated renditions
echo removing $ICONSET_FOLDER folder
rm -rf $ICONSET_FOLDER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment