Skip to content

Instantly share code, notes, and snippets.

@seven1240
Forked from ahmed-musallam/generate-icns.sh
Created November 10, 2021 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seven1240/9cb5a59ae10b00208f123b711ec31ad7 to your computer and use it in GitHub Desktop.
Save seven1240/9cb5a59ae10b00208f123b711ec31ad7 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
# Required deps:
# imagemagick: https://imagemagick.org/script/download.php
# name of your master icon, must be at least 512X512
PNG_MASTER="icon-large.png"
ICONSET_FOLDER="AppIcon.iconset"
sizes=(
16x16
32x32
128x128
256x256
512x512
)
# 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 $ICONSET_FOLDER/$icon
icon="icon_${size}@2x.png"
ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
echo Generating $ICONSET_FOLDER/$icon
convert $PNG_MASTER -quality 100 -resize $size $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}@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