Last active
August 29, 2015 14:06
Revisions
-
swarminglogic revised this gist
Sep 5, 2014 . 1 changed file with 6 additions and 6 deletions.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 @@ -1,6 +1,7 @@ #!/bin/bash # pngopt: A wrapper for pngcrush, that makes it easier to use for overriding # images with its optimized output. # # use: pngopt FILE1 [FILE2] [FILE3] ... # @@ -13,21 +14,20 @@ # while test $# -gt 0; do if [ ! -f "$1" ] ; then echo "Error: Bad input file: $1" >&2 shift continue fi tmpfile=$(tempfile --suffix ".png") pngcrush "$1" $tmpfile > /dev/null filesizes=$(ls -l "$1" $tmpfile | awk '{print $5}' | xargs echo) if <<<$filesizes awk '{exit !($1 > $2)}' ; then echo -n "$1 " <<<$filesizes awk '{printf "(%.2f", (100 * ($1/$2 - 1)) ; print " %)"}' cp $tmpfile "$1" rm $tmpfile fi shift done -
swarminglogic revised this gist
Sep 5, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Empty file. -
swarminglogic renamed this gist
Sep 5, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
swarminglogic created this gist
Sep 5, 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,33 @@ #!/bin/bash # pngopt: A wrapper for pngcrush, that makes it easier to use for overriding images with its optimized output. # # use: pngopt FILE1 [FILE2] [FILE3] ... # # If a file is optimized it outputs the filename with percentage reduction. # # # Example use: # To replace filea.png and fileb.png with its optimized counterpart: # $ pngopt filea.png fileb.png # while test $# -gt 0; do if [ ! -f $1 ] ; then echo "Error: Bad input file: $1" >&2 shift continue fi tmpfile=$(tempfile --suffix ".png") pngcrush "$1" $tmpfile > /dev/null if ls -l $1 $tmpfile | awk '{print $5}' | xargs echo | awk '{exit !($1 > $2)}' ; then echo -n "$1 " ls -l $1 $tmpfile | awk '{print $5}' | xargs echo | \ awk '{print "("(100 * ($1/$2 - 1))" %)"}' cp $tmpfile "$1" rm $tmpfile fi shift done