This repository was archived by the owner on Sep 9, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change 1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515function get_size {
16- LS_OUTPUT=($( ls -n $1 ) ) ;
17- echo ${LS_OUTPUT[4]} ;
16+ LS_OUTPUT=($( ls -n " $1 " ) )
17+ echo ${LS_OUTPUT[4]}
1818}
1919
20- FILENAME=$1 ;
21- OUTFILE=' /tmp/git-lint/optipng.png' ;
22- origsize=$( get_size $FILENAME ) ;
23- rm $OUTFILE 2> /dev/null;
24- optipng -out $OUTFILE -o9 $FILENAME > /dev/null 2> /dev/null;
25- newsize=$( get_size $OUTFILE ) ;
20+ FILENAME=$1
21+ OUTFILE=" $( mktemp) "
22+ ORIGSIZE=$( get_size " $FILENAME " )
23+ rm " $OUTFILE " 2> /dev/null
24+ optipng -out " $OUTFILE " -o9 " $FILENAME " > /dev/null 2> /dev/null
25+ NEWSIZE=$( get_size " $OUTFILE " )
26+ rm " $OUTFILE " 2> /dev/null
2627
27- if [ $newsize -gt 0 ] && [ $newsize -lt $origsize ]; then
28- reduction= ` bc <<< " scale = 2; (100*($origsize - $newsize ) / $origsize) " ` ;
29- echo " The file size can be losslessly reduced from $origsize to $newsize bytes. ($reduction % filesize reduction)" ;
30- echo " Use: optipng -o9 $FILENAME " ;
31- exit 1;
28+ if [ " $NEWSIZE " != " " ] && [ " $NEWSIZE " -gt 0 ] && [ " $NEWSIZE " -lt " $ORIGSIZE " ]; then
29+ REDUCTION= $( bc <<< " scale = 2; (100*($ORIGSIZE - $NEWSIZE ) / $ORIGSIZE) " )
30+ echo " The file size can be losslessly reduced from $ORIGSIZE to $NEWSIZE bytes. ($REDUCTION % filesize reduction)"
31+ echo " Use: optipng -o9 $FILENAME "
32+ exit 1
3233fi
You can’t perform that action at this time.
0 commit comments