Skip to content

Instantly share code, notes, and snippets.

@martinbutt
Created May 23, 2024 05:27
Show Gist options
  • Save martinbutt/57bfdb6c3b9e4e6aebbe6d1249516fa0 to your computer and use it in GitHub Desktop.
Save martinbutt/57bfdb6c3b9e4e6aebbe6d1249516fa0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Script to generate all the icon sizes from the 256x256@2x set
usage() {
echo "Usage: $(basename $0) path-to-icons"
}
if ! command -v convert &> /dev/null
then
echo "ERROR: 'convert' command not found. Install imagemagick."
exit 1
fi
if [ -z "$1" ]; then
echo "ERROR: path to icons not set."
usage
exit 1
fi
pushd $1 2>/dev/null || (echo "ERROR: Unable to access directory '$1'." && exit 1)
if [ ! -d 256x256@2x ]; then echo "no '256x256@2x' folder in $1. Create this first with the 512x512 icons."; exit 1; fi
if [ ! -d 16x16 ]; then mkdir 16x16; fi
if [ ! -d 16x16@2x ]; then mkdir 16x16@2x; fi
if [ ! -d 24x24 ]; then mkdir 24x24; fi
if [ ! -d 24x24@2x ]; then mkdir 24x24@2x; fi
if [ ! -d 32x32 ]; then mkdir 32x32; fi
if [ ! -d 32x32@2x ]; then mkdir 32x32@2x; fi
if [ ! -d 48x48 ]; then mkdir 48x48; fi
if [ ! -d 48x48@2x ]; then mkdir 48x48@2x; fi
if [ ! -d 256x256 ]; then mkdir 256x256; fi
for category in 256x256@2x/*; do
if [ -d "${category}" ]; then
for icon in "${category}"/*; do
convert "${icon}" -resize 16x16 "${icon//256x256@2x/16x16/}"
convert "${icon}" -resize 32x32 "${icon//256x256@2x/16x16@2x/}"
convert "${icon}" -resize 32x32 "${icon//256x256@2x/32x32/}"
convert "${icon}" -resize 24x24 "${icon//256x256@2x/24x24/}"
convert "${icon}" -resize 48x48 "${icon//256x256@2x/24x24@2x/}"
convert "${icon}" -resize 48x48 "${icon//256x256@2x/48x48/}"
convert "${icon}" -resize 64x64 "${icon//256x256@2x/32x32@2x/}"
convert "${icon}" -resize 96x96 "${icon//256x256@2x/48x48@2x/}"
convert "${icon}" -resize 256x256 "${icon//256x256@2x/256x256/}"
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment