Image optimization bash script
Go to file
2018-10-29 19:20:53 +01:00
crons improve cronjobs 2018-08-07 15:27:37 +02:00
docs update README informations 2018-10-29 19:11:04 +01:00
.gitignore add command arguments 2018-10-24 07:47:01 +02:00
img-optimize.png update screenshot 2018-08-10 06:35:13 +02:00
install-optipng.sh comment bash script 2018-07-30 14:36:29 +02:00
install-webp.sh comment bash script 2018-07-30 14:36:29 +02:00
LICENSE Initial commit 2016-10-16 18:27:04 +02:00
optimize.sh make optimize.sh executable 2018-10-29 19:20:53 +01:00
README.md update README informations 2018-10-29 19:11:04 +01:00

Bash script to optimize your images and convert them in WebP

img-optimize

Prerequisite

  • jpegoptim
  • optipng
  • WebP

Debian/Ubuntu :

sudo apt install jpegoptim optipng webp -y

Centos 7 :

sudo yum install optipng jpegoptim libwebp-tools -y

Installation

  1. Download the script and make it executable
wget -O $HOME/optimize.sh https://raw.githubusercontent.com/VirtuBox/wp-optimize/master/optimize.sh
chmod +x $HOME/optimize.sh
  1. Add an alias in your bashrc
echo "alias img-optimize=$HOME/optimize.sh" >> $HOME/.bashrc
source $HOME/.bashrc

Usage

Usage: img-optimize [options] <image path>
  Options:
       --jpg <image path> ..... optimize all jpg images
       --png <image path> ..... optimize all png images
       --webp <image path> ..... convert all images in webp
       --nowebp <image path> ..... optimize all png & jpg images
       --all <image path> ..... optimize all images (png + jpg + webp)
 Other options :
       -h, --help, help ... displays this help information
Examples:
  optimize all jpg images in /var/www/images
    img-optimize --jpg /var/www/images

Warning

Conversion process can take a while, you can use tmux to launch the script and be able to close your ssh connection without interrupting conversion. Then just use tmux attach to login back in your tmux session.

Credits

WebP conversion script is inspired by this DigitalOcean Community Tutorial