set image path as optional

This commit is contained in:
VirtuBox 2019-03-20 01:38:32 +01:00
parent 42dc003ec3
commit c8bc9ae00b
2 changed files with 43 additions and 24 deletions

View File

@ -40,19 +40,19 @@ source $HOME/.bashrc
### Usage ### Usage
```bash ```bash
Usage: img-optimize [options] <image path> Usage: img-optimize [options] <images path>
If images path is not defined, img-optimize will use the current directory
Options: Options:
--jpg <image path> ..... optimize all jpg images --jpg <images path> ..... optimize all jpg images
--png <image path> ..... optimize all png images --png <images path> ..... optimize all png images
--webp <image path> ..... convert all images in webp --webp <images path> ..... convert all images in webp
--nowebp <image path> ..... optimize all png & jpg images --nowebp <images path> ..... optimize all png & jpg images
--all <image path> ..... optimize all images (png + jpg + webp) --all <images path> ..... optimize all images (png + jpg + webp)
Other options : Other options :
-h, --help, help ... displays this help information -h, --help, help ... displays this help information
Examples: Examples:
optimize all jpg images in /var/www/images optimize all jpg images in /var/www/images
img-optimize --jpg /var/www/images img-optimize --jpg /var/www/images
``` ```
### Update the script ### Update the script

View File

@ -18,13 +18,14 @@ CGREEN="${CSI}1;32m"
_help() { _help() {
echo "Bash script to optimize your images and convert them in WebP " echo "Bash script to optimize your images and convert them in WebP "
echo "Usage: img-optimize [options] <image path>" echo "Usage: img-optimize [options] <images path>"
echo "If images path isn't defined, img-optimize will use the current directory "
echo " Options:" echo " Options:"
echo " --jpg <image path> ..... optimize all jpg images" echo " --jpg <images path> ..... optimize all jpg images"
echo " --png <image path> ..... optimize all png images" echo " --png <images path> ..... optimize all png images"
echo " --webp <image path> ..... convert all images in webp" echo " --webp <images path> ..... convert all images in webp"
echo " --nowebp <image path> ..... optimize all png & jpg images" echo " --nowebp <images path> ..... optimize all png & jpg images"
echo " --all <image path> ..... optimize all images (png + jpg + webp)" echo " --all <images path> ..... optimize all images (png + jpg + webp)"
echo " Other options :" echo " Other options :"
echo " -h, --help, help ... displays this help information" echo " -h, --help, help ... displays this help information"
echo "Examples:" echo "Examples:"
@ -43,38 +44,56 @@ if [ "${#}" = "0" ]; then
exit 1 exit 1
else else
while [ ${#} -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "${1}" in case "$1" in
--jpg) --jpg)
JPG_OPTIMIZATION="y" JPG_OPTIMIZATION="y"
if [ "$2" ]; then if [ "$2" ]; then
IMG_PATH=$2 IMG_PATH=$2
fi
shift shift
else
IMG_PATH="./*"
fi
;; ;;
--png) --png)
PNG_OPTIMIZATION="y" PNG_OPTIMIZATION="y"
if [ "$2" ]; then
IMG_PATH=$2 IMG_PATH=$2
shift shift
else
IMG_PATH="./*"
fi
;; ;;
--nowebp) --nowebp)
JPG_OPTIMIZATION="y" JPG_OPTIMIZATION="y"
PNG_OPTIMIZATION="y" PNG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="n" WEBP_OPTIMIZATION="n"
if [ "$2" ]; then
IMG_PATH=$2 IMG_PATH=$2
shift shift
else
IMG_PATH="./*"
fi
;; ;;
--webp) --webp)
WEBP_OPTIMIZATION="y" WEBP_OPTIMIZATION="y"
if [ "$2" ]; then
IMG_PATH=$2 IMG_PATH=$2
shift shift
else
IMG_PATH="./*"
fi
;; ;;
--all) --all)
PNG_OPTIMIZATION="y" PNG_OPTIMIZATION="y"
JPG_OPTIMIZATION="y" JPG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="y" WEBP_OPTIMIZATION="y"
if [ "$2" ]; then
IMG_PATH=$2 IMG_PATH=$2
shift shift
else
IMG_PATH="./*"
fi
;; ;;
-h | --help | help) -h | --help | help)
_help _help