Created
September 1, 2014 04:53
-
-
Save thebaer/fc77784cc0fb8fd1efcf to your computer and use it in GitHub Desktop.
Revisions
-
thebaer created this gist
Sep 1, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/bin/bash # Make the given file(s) the given dimension, by extending the canvas, rather # than scaling. Made especially for PNGs, since it makes the background # transparent and all. This programmer in particular has found it useful for # different-sized icons that end at their exact boundaries, causing headaches # when developing Android apps. # Name some args FINALSIZE=$1 # Gotta have some parameters to continue # First parameter should be image dimensions, i.e. contain 'x' in the middle. if [ -z "$FINALSIZE" ] || [[ $FINALSIZE != *x* ]]; then if [[ $FINALSIZE != *x* ]]; then echo "desired-size not given!" fi echo "usage: normalizeicons.sh desired-size file [file2 ...]" echo " desired-size: Desired image dimensions, e.g. 164x120" echo exit 1 fi # Make sure we've got the magic butter hash convert 2>/dev/null || { echo >&2 "MISSING convert COMMAND! INSTALL ImageMagick TO CONTINUE."; echo; exit 1; } for INFILE in ${@:2}; do FILENAME=$(basename $INFILE) # Do the stuff # If your grays are fine, use this. Otherwise comment out, and use command below. convert $INFILE -background transparent -gravity center -extent $FINALSIZE $FILENAME # Sometimes this script messes up grays in your PNGs. If so, uncomment this: #convert $INFILE -define png:big-depth=16 -define png:color-type=6 -background transparent -gravity center -extent $FINALSIZE $FILENAME done