Created
March 19, 2024 13:34
-
-
Save okinjp/ed78071cc96e4175cd9ad85bbfa9110f to your computer and use it in GitHub Desktop.
Generate resized icons for mastodon
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
#!/bin/bash | |
if [ -z $(which convert) ];then | |
echo "Missing ImageMagick. Aborted." | |
exit 1 | |
fi | |
TARGET_IMAGE=${1} | |
if [ -z "${TARGET_IMAGE}" ] || [ ! -f "${TARGET_IMAGE}" ];then | |
echo "Missing image. Aborted." | |
exit 2 | |
fi | |
GEN_DIR=mastodon-icons-`date '+%Y%m%d'` | |
PREFIX=("android-chrome" "apple-touch-icon" "favicon") | |
G_SIZES=("36" "48" "72" "96" "144" "192" "256" "384" "512") | |
A_SIZES=("1024" "180" "167" "152" "144" "120" "114" "76" "72" "60" "57") | |
W_SIZES=("16" "32" "48") | |
resize_square() { | |
INPUTFILE=${1} | |
TOSIZE=${2:-"512"} | |
PREFIX=${3:-"favicon"} | |
OUTPUTFILE=${GEN_DIR}/${PREFIX}-${TOSIZE}x${TOSIZE}.png | |
convert $INPUTFILE -resize ${TOSIZE}x${TOSIZE}! $OUTPUTFILE | |
} | |
# MKDIR | |
mkdir -p ${GEN_DIR} | |
# for android | |
for el in "${G_SIZES[@]}"; do | |
resize_square ${TARGET_IMAGE} ${el} ${PREFIX[0]} | |
done | |
# for apple | |
for el in "${A_SIZES[@]}"; do | |
resize_square ${TARGET_IMAGE} ${el} ${PREFIX[1]} | |
done | |
# for favicon | |
for el in "${W_SIZES[@]}"; do | |
resize_square ${TARGET_IMAGE} ${el} ${PREFIX[2]} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment