Skip to content

Instantly share code, notes, and snippets.

@andresaquino andresaquino/iconresize.sh
Last active Jan 27, 2019

Embed
What would you like to do?
Resize icon using imagemagick or ffmpeg
#!/usr/bin/env bash
#
# Install:
# cp iconresize.sh ~/bin/iconresize
# chmod 0700 ~/bin/iconresize
#
# How to use:
# iconresize <filename:icon.png> <directory:android> <tool:im|ff>
#
# Where:
# im means ImageMagick (default)
# ff means ffmpeg
#
# Example:
# iconresize icon.png zabbix
#
__imgSource=${1:-icon.png}
__imgDest=${__imgSource%.*}
__imgRepository=${2:-Icons}
__imgTool=${3:-im}
#
[ -f ${__imgSource} ] || exit 0
[ -d ${__imgRepository} ] || mkdir -p ${__imgRepository}
__imgSizes=(
"24x1" "48x1" "64x1" "96x1" "128x1"
"20x1" "20x2" "20x3"
"29x1" "29x2" "29x3"
"40x1" "40x2" "40x3"
"60x2" "60x3"
"76x1" "76x2"
"83.5x2" "1024x1"
)
# resizing
for eSize in ${__imgSizes[*]}; do
size=${eSize%x*}
scale=${eSize##*x}
resize=$((${size}*${scale}))
echo "resizing ${__imgSource} to ${size}x${size}@${scale}"
if [[ "${__imgTool}" == "ff" ]]; then
ffmpeg -loglevel "quiet" \
-i ${__imgSource} \
-yvf scale=${resize}:-1 \
${__imgRepository}/Icon-${__imgDest}-${size}x${size}@${scale}x.png
else
# using imagemagick
convert ${__imgSource} \
-resize ${resize}x${resize} \
-unsharp '1.5x1+0.7+0.02' \
${__imgRepository}/Icon-${__imgDest}-${size}x${size}@${scale}x.png
fi
done
@andresaquino

This comment has been minimized.

Copy link
Owner Author

andresaquino commented Jan 27, 2019

Original
ic-server

Resizing
icon-ic-server-24x24 1x
icon-ic-server-48x48 1x
icon-ic-server-64x64 1x
icon-ic-server-96x96 1x
icon-ic-server-128x128 1x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.