Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtuBox committed Mar 20, 2019
1 parent d41b486 commit 42dc003
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 48 deletions.
6 changes: 3 additions & 3 deletions install-optipng.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
sudo apt-get install build-essential libpng-dev -y

# go into /usr/local/src and remove previous optipng folder/archive
cd /usr/local/src
cd /usr/local/src || exit 1
rm -rf optipng*

# get the latest optipng release link
OPTIPNGLATEST=$(wget http://optipng.sourceforge.net/ -O - | grep tar.gz | awk -F "[\"]" '{print $4}')
OPTIPNGLATEST=$(wget http://optipng.sourceforge.net/ -O - | grep tar.gz | awk -F '["]' '{print $4}')

# download and extract optipng
wget $OPTIPNGLATEST -O optipng.tar.gz
tar -xf optipng.tar.gz
cd optipng-*
cd optipng-* || exit 1

# configure and compile optipng
./configure --prefix=/usr
Expand Down
109 changes: 64 additions & 45 deletions optimize.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#!/bin/bash
#----------------------------------------------------------------------------
# img-optimize- Image optimization bash script
#----------------------------------------------------------------------------
# Website: https://virtubox.net
# GitHub: https://github.com/VirtuBox/img-optimize
# Author: VirtuBox
# License: M.I.T
# ----------------------------------------------------------------------------
# Version 1.0 - 2019-03-20
# ----------------------------------------------------------------------------

#!/bin/bash
CSI='\033['
CEND="${CSI}0m"
Expand Down Expand Up @@ -26,46 +38,53 @@ _help() {
# Parse script arguments
##################################

while [[ $# -gt 0 ]]; do
arg="$1"
case $arg in
--jpg)
JPG_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
--png)
PNG_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
--nowebp)
JPG_OPTIMIZATION="y"
PNG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="n"
IMG_PATH=$2
shift
;;
--webp)
WEBP_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
--all)
PNG_OPTIMIZATION="y"
JPG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
-h | --help | help)
_help
exit 1
;;
*) ;;
esac
shift
done
if [ "${#}" = "0" ]; then
_help
exit 1
else

while [ ${#} -gt 0 ]; do
case "${1}" in
--jpg)
JPG_OPTIMIZATION="y"
if [ "$2" ]; then
IMG_PATH=$2
fi
shift
;;
--png)
PNG_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
--nowebp)
JPG_OPTIMIZATION="y"
PNG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="n"
IMG_PATH=$2
shift
;;
--webp)
WEBP_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
--all)
PNG_OPTIMIZATION="y"
JPG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="y"
IMG_PATH=$2
shift
;;
-h | --help | help)
_help
exit 1
;;
*) ;;
esac
shift
done
fi

##################################
# Welcome
Expand Down Expand Up @@ -110,13 +129,13 @@ if [ "$JPG_OPTIMIZATION" = "y" ]; then
echo -ne ' jpg optimization [..]\r'
cd $IMG_PATH || exit 1
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 jpegoptim --preserve --strip-all -m82

echo -ne " jpg optimization [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
fi
if [ "$PNG_OPTIMIZATION" = "y" ]; then
# optimize png

echo -ne ' png optimization [..]\r'
cd $IMG_PATH || exit 1
find . -type f -iname '*.png' -print0 | xargs -0 optipng -o7 -strip all
Expand All @@ -129,16 +148,16 @@ if [ "$WEBP_OPTIMIZATION" = "y" ]; then
cd $IMG_PATH || exit 1
find . -type f -iname "*.png" -print0 | xargs -0 -I {} \
bash -c '[ ! -f "{}.webp" ] && { cwebp -z 9 -mt {} -o {}.webp; }'

echo -ne " png to webp conversion [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'

# convert jpg to webp
echo -ne ' jpg to webp conversion [..]\r'
cd $IMG_PATH || exit 1
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 -I {} \
bash -c '[ ! -f "{}.webp" ] && { cwebp -q 82 -mt {} -o {}.webp; }'

echo -ne " jpg to webp conversion [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
fi
Expand Down

0 comments on commit 42dc003

Please sign in to comment.