Last active
January 27, 2019 16:33
-
-
Save andresaquino/3c28a7641d4182159b6cd033edcf2878 to your computer and use it in GitHub Desktop.
Resize icon using imagemagick or ffmpeg
This file contains hidden or 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
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original

Resizing




