Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
zevilz committed Feb 27, 2018
2 parents 98ef539 + c7214fb commit e089ac7
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 17 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ bash zImageOptimizer.sh --path=/path/to/files
```

Supported options:
- -h (--help) - shows help,
- -v (--version) - shows script version,
- -p (--path) - specify full path to input directory (usage: `-p <dir> | --path=<dir>`),
- -q (--quiet) - execute script without any questions and users actions,
- -l (--less) - don't show optimizing process,
- -c (--check-only) - check tools with an opportunity to install dependences,
- -t (--time) - set period for which to look for files by last modified time (usage: `-t <period> | --time=<period>`),
- -n (--new-only) - use time marker file for looking new images only,
- -m (--time-marker) - set custom full path or custom filename of time marker file (usage: `-m <name|path> | --time-marker=<name|path>`),
- -tmp (--tmp-path) - set custom directory full path for temporary files (usage: `-tmp <dir> | --tmp-path=<dir>`).
- -h (--help) - shows help;
- -v (--version) - shows script version;
- -p (--path) - specify full path to input directory (usage: `-p <dir> | --path=<dir>`);
- -q (--quiet) - execute script without any questions and users actions;
- -l (--less) - don't show optimizing process;
- -c (--check-only) - check tools with an opportunity to install dependences;
- -t (--time) - set period for which to look for files by last modified time (usage: `-t <period> | --time=<period>`);
- -n (--new-only) - use time marker file for looking new images only;
- -m (--time-marker) - set custom full path or custom filename of time marker file (usage: `-m <name|path> | --time-marker=<name|path>`);
- -tmp (--tmp-path) - set custom directory full path for temporary files (usage: `-tmp <dir> | --tmp-path=<dir>`);
- -e (--exclude) - comma separated parts list of paths to files for exclusion from search (script removes from the search files in the full path of which includes any value from the list; usage: `-e <list> | --exclude=<list>`).

Notices:
- you may combine options;
Expand All @@ -63,6 +64,16 @@ Notices:
- it is impossible to use together options -t(--time) and -n(--new-only);
- you must use option -m(--time-marker) with -n(--new-only) option.

### Excluding folders/files from search
```bash
bash zImageOptimizer.sh -p /path/to/files -e <list>
```

Example:
```bash
bash zImageOptimizer.sh -p /path/to/files -e /var/www/test.com,backup,uploads/orig.png
```

### Usage with set period
```bash
bash zImageOptimizer.sh -p /path/to/files -t <period>
Expand Down Expand Up @@ -317,7 +328,7 @@ You have not write access to directory /tmp. Tools djpeg and cjpeg use this dire
- [ ] add SVG support
- [ ] add logging
- [ ] add Ansible playbook
- [ ] add progrees indicator
- [x] ~~add progrees indicator~~

## Contacts
- telegram [@zevilz](https://t.me/zevilz) (EN|RU)
Expand All @@ -332,6 +343,7 @@ Do you like script? Would you like to support its development? Feel free to dona
[![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.me/zevilz)

## Changelog
- 27.02.2018 - 0.9.1 - [added new features](https://github.com/zevilz/zImageOptimizer/releases/tag/0.9.1) and bugfixes
- 25.02.2018 - 0.9.0 - added support for working script on MacOS 10.10+ with automatic install dependences
- 24.02.2018 - 0.8.1 - [added new parameter, updated info after optimizing, small fixes and small code refactoring](https://github.com/zevilz/zImageOptimizer/releases/tag/0.8.1)
- 04.12.2017 - 0.8.0 - [new features, bugfixes and code refactoring](https://github.com/zevilz/zImageOptimizer/releases/tag/0.8.0)
Expand Down
71 changes: 65 additions & 6 deletions zImageOptimizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# URL: https://github.com/zevilz/zImageOptimizer
# Author: Alexandr "zEvilz" Emshanov
# License: MIT
# Version: 0.9.0
# Version: 0.9.1

# Define default vars
BINARY_PATHS="/bin /usr/bin /usr/local/bin"
Expand Down Expand Up @@ -571,6 +571,29 @@ readableSize()
echo -n $(echo "scale=1; $1/1024" | bc | sed 's/^\./0./')"Kb"
fi
}
readableTime()
{
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( $D > 0 )) && printf '%d days ' $D
(( $H > 0 )) && printf '%d hours ' $H
(( $M > 0 )) && printf '%d minutes ' $M
(( $D > 0 || $H > 0 || $M > 0 )) && printf 'and '
printf '%d seconds\n' $S
}

findExclude()
{
if ! [ -z "$EXCLUDE_LIST" ]; then
EXCLUDE_LIST=$(echo $EXCLUDE_LIST | sed 's/,$//g' | sed 's/^,//g' | sed 's/,/\\|/g')
grep -v "$EXCLUDE_LIST"
else
grep -v ">>>>>>>>>>>>>"
fi
}

usage()
{
Expand Down Expand Up @@ -624,6 +647,11 @@ usage()
echo " --tmp-path=<dir> Default value located in TMP_PATH variable "
echo " (/tmp by default)"
echo
echo " -e <list>, Comma separated parts list of paths to files "
echo " --exclude=<list> for exclusion from search. The script removes "
echo " from the search files in the full path of which "
echo " includes any value from the list."
echo
}

# Define inner default vars. Don't change them!
Expand All @@ -636,6 +664,7 @@ CHECK_ONLY=0
PERIOD=0
NEW_ONLY=0
TIME_MARKER=""
EXCLUDE_LIST=""
PARAMS_NUM=$#

while [ 1 ] ; do
Expand All @@ -659,6 +688,11 @@ while [ 1 ] ; do
elif [ "$1" = "-tmp" ] ; then
shift ; TMP_PATH="$1"

elif [ "${1#--exclude=}" != "$1" ] ; then
EXCLUDE_LIST="${1#--exclude=}"
elif [ "$1" = "-e" ] ; then
shift ; EXCLUDE_LIST="$1"

elif [[ "$1" = "--help" || "$1" = "-h" ]] ; then
HELP=1

Expand Down Expand Up @@ -904,7 +938,7 @@ else
fi
fi

IMAGES=`\
IMAGES=$(\
find "$DIR_PATH" $FIND_INCLUDE \( \
-name '*.jpg' -or \
-name '*.jpeg' -or \
Expand All @@ -914,9 +948,9 @@ find "$DIR_PATH" $FIND_INCLUDE \( \
-name '*.GIF' -or \
-name '*.png' -or \
-name '*.PNG' \
\)`
\) | findExclude)

IMAGES_TOTAL=`\
IMAGES_TOTAL=$(\
find "$DIR_PATH" $FIND_INCLUDE \( \
-name '*.jpg' -or \
-name '*.jpeg' -or \
Expand All @@ -926,9 +960,11 @@ find "$DIR_PATH" $FIND_INCLUDE \( \
-name '*.GIF' -or \
-name '*.png' -or \
-name '*.PNG' \
\) | wc -l`
\) | findExclude | wc -l)

IMAGES_OPTIMIZED=0
IMAGES_CURRENT=0
START_TIME=$(date +%s)

if ! [ -z "$IMAGES" ]; then

Expand All @@ -941,6 +977,21 @@ if ! [ -z "$IMAGES" ]; then
echo "$IMAGES" | ( while read IMAGE ; do

if [ $LESS -eq 0 ]; then
# if [ $SHOW_PROGRESS -eq 1 ]; then
# if [ $PROGRESS_MEASURE == "percent" ]; then
# IMAGES_CURRENT_PERCENT=$(echo "scale=2; $IMAGES_CURRENT*100/$IMAGES_TOTAL" | bc)
# IMAGES_CURRENT=$(echo "$IMAGES_CURRENT+1" | bc)
# echo -n "[$IMAGES_CURRENT_PERCENT%] "
# fi
# if [ $PROGRESS_MEASURE == "num" ]; then
IMAGES_CURRENT=$(echo "$IMAGES_CURRENT+1" | bc)
echo -n "["
echo -n $IMAGES_CURRENT
echo -n "/"
echo -n $IMAGES_TOTAL
echo -n "] "
# fi
# fi
echo -n "$IMAGE"
echo -n '... '
fi
Expand Down Expand Up @@ -1035,7 +1086,15 @@ if ! [ -z "$IMAGES" ]; then
readableSize $SAVED_SIZE
echo " / $(echo "scale=2; 100-$OUTPUT*100/$INPUT" | bc | sed 's/^\./0./')%"

echo "Optimized/Total: $IMAGES_OPTIMIZED / $IMAGES_TOTAL files"
echo -n "Optimized/Total: "
echo -n $IMAGES_OPTIMIZED
echo -n " / "
echo -n $IMAGES_TOTAL
echo " files"
END_TIME=$(date +%s)
TOTAL_TIME=$(echo "$END_TIME-$START_TIME" | bc)
echo -n "Total optimizing time: "
readableTime $TOTAL_TIME
)
updateTimeMarker

Expand Down

0 comments on commit e089ac7

Please sign in to comment.