├── LICENSE ├── PNGCompress ├── README.md ├── pngquant └── pngquantWrapper /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Asha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PNGCompress: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ]; then 3 | echo usage: compressimg [directory or file] 4 | exit 5 | fi 6 | 7 | # apply the compressimg script to every image file within the given directory 8 | # if the input is a single file, execute the script on it 9 | OLDSIZE=`du -sk $1 | awk '{ print $1}'` 10 | # echo 'OLDSIZE' 11 | # echo $OLDSIZE 12 | INPUTTYPE="Directory" 13 | 14 | # execute compression 15 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 16 | if [ -d $1 ]; then 17 | find $1 -type f \( -name "*.png" \) -exec $DIR/pngquantWrapper '{}' \; 18 | else 19 | INPUTTYPE="File" 20 | $DIR/pngquantWrapper $1 21 | fi 22 | 23 | NEWSIZE=`du -sk $1 | awk '{ print $1}'` 24 | let RESULT=100-$NEWSIZE*100/$OLDSIZE 25 | echo '' 26 | echo $1 Finished. 27 | echo 'NEWSIZE/OLDSIZE' $NEWSIZE'/'$OLDSIZE 28 | echo 'TOTAL:'$RESULT'% COMPRESSED.' 29 | echo '' 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PNGCompressForMac 2 | Simple shell script to compress png file. It will compress all png file include in given directory. 3 | 4 | ## USAGE 5 | ``` 6 | sh PNGCompress PATH/TO/YOUR/RES 7 | ``` 8 | 9 | ## NOTICE 10 | MacOS **only** 11 | 12 | ## Reference 13 | * [pngquant](https://pngquant.org/) 14 | * [Optimize-Images GitHub](https://github.com/johnellmore/Optimize-Images) 15 | -------------------------------------------------------------------------------- /pngquant: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashqal/PNGCompressForMac/2038bf576ebea8f1922b547c4c3a2bfbd1853e0b/pngquant -------------------------------------------------------------------------------- /pngquantWrapper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ]; then 3 | echo usage: compressimg [file] 4 | echo This tool will apply common image optimization techniques to the given file. 5 | exit 6 | fi 7 | OLDSIZE=`ls -l $1 | awk '{ print $5}'` 8 | 9 | ./pngquant --force --skip-if-larger $1 --output $1.tmp 10 | 11 | if [ -f $1.tmp ]; then 12 | mv $1.tmp $1 13 | fi 14 | 15 | NEWSIZE=`ls -l $1 | awk '{ print $5}'` 16 | 17 | # show final stats 18 | let RESULT=100-$NEWSIZE*100/$OLDSIZE 19 | echo $1 $NEWSIZE'/'$OLDSIZE ' - ['$RESULT'% COMPRESSED]' 20 | --------------------------------------------------------------------------------