Skip to content

Instantly share code, notes, and snippets.

@benallfree
Last active May 28, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benallfree/bbe42b418f613ca97014717fb3e7dfd5 to your computer and use it in GitHub Desktop.
Save benallfree/bbe42b418f613ca97014717fb3e7dfd5 to your computer and use it in GitHub Desktop.
electron-react-boilerplate icon generation
#!/bin/bash
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/..
RSC="$ROOT/resources"
SRC="${RSC}/icons/1024x1024.png"
echo $SRC
if [ ! -f "$SRC" ]; then
echo "Please create resources/icons/1024x1024.png before running this script."
exit
fi
rm -f "$RSC/icon.ico" "$RSC/icon.icns" "$RSC/icon.png"
# Declare an array of string with type
declare -a sizes=("16 24 32 48 64 96 128 256 512" )
# Iterate the string array using for loop
for size in ${sizes[@]}; do
DST="$RSC/icons/${size}x${size}.png"
echo $DST
rm -f $DST
convert -resize ${size}x${size}! "$SRC" "$DST"
done
cp "$RSC"/icons/256x256.png "$RSC"/icon.png
ICONSET="$ROOT"/.tmp/Icons.iconset
mkdir -p "$ICONSET"
echo $ICONSET
sips -z 16 16 "$SRC" --out "$ICONSET"/icon_16x16.png
sips -z 32 32 "$SRC" --out "$ICONSET"/icon_16x16@2x.png
sips -z 32 32 "$SRC" --out "$ICONSET"/icon_32x32.png
sips -z 64 64 "$SRC" --out "$ICONSET"/icon_32x32@2x.png
sips -z 128 128 "$SRC" --out "$ICONSET"/icon_128x128.png
sips -z 256 256 "$SRC" --out "$ICONSET"/icon_128x128@2x.png
sips -z 256 256 "$SRC" --out "$ICONSET"/icon_256x256.png
sips -z 512 512 "$SRC" --out "$ICONSET"/icon_256x256@2x.png
sips -z 512 512 "$SRC" --out "$ICONSET"/icon_512x512.png
cp "$SRC" "$ICONSET"/icon_512x512@2x.png
iconutil -c icns -o "$RSC/icon.icns" "$ICONSET"
convert "$RSC/icons"/16x16.png "$RSC/icons"/32x32.png "$RSC/icons"/48x48.png "$RSC/icons"/64x64.png "$RSC/icons"/128x128.png "$RSC/icons"/256x256.png "$RSC"/icon.ico
cp "$RSC"/icon.icns "$ROOT"/app/app.icns
rm -rf "$ICONSET"
@1mike12
Copy link

1mike12 commented May 8, 2020

ty, as a noob I would add
#place script in $ProjectRoot/resources/ and run with sh iconify.sh
#requires the convert command line tool, available from brew install imagemagick on macOS

@codereviewvideos
Copy link

Thanks for making & sharing.

It wasn't immediately obvious to me, but this will only run on OSX due to the sips command. Likely there is a Linux equivalent, but I'm not skilled enough to know what it is.

@benallfree
Copy link
Author

benallfree commented May 28, 2020

@codereviewvideos

It wasn't immediately obvious to me, but this will only run on OSX due to the sips command. Likely there is a Linux equivalent, but I'm not skilled enough to know what it is.

Look at convert from imagemagick. If you can get that working please post your solution because I think others wouldn value it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment