You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
VirtuBox 0fa994d9ec
update github page
1 year ago
crons add daily cronjob instructions & optimize script 1 year ago
docs update github page 1 year ago
images Add travis 1 year ago
scripts Add scripts to compile optipng & libwebp 1 year ago
.gitignore add command arguments 2 years ago
.travis.yml Add scripts to compile optipng & libwebp 1 year ago Add scripts to compile optipng & libwebp 1 year ago
LICENSE Initial commit 4 years ago Fix dead link 1 year ago
img-optimize.png update screenshot 2 years ago Fix $FIND_ARGS 1 year ago

Image optimization bash script


Travis GitHub GitHub release GitHub last commit Github stars


  • jpegoptim for jpg optimization
  • optipng for png optimization
  • cwebp for WebP conversion

From APT repositories

Debian/Ubuntu :

sudo apt install jpegoptim optipng webp -y

Centos 7 :

sudo yum install optipng jpegoptim libwebp-tools -y

Compile the latest release (optipng & libwebp)

For Debian/Ubuntu (available in scripts folder) :

# optipng
curl -sL | sudo -E bash

# libwebp
curl -sL | sudo -E bash


  1. Clone the repository
git clone $HOME/.img-optimize
  1. Install the script

Method 1 : Add an alias in .bashrc

With this method img-optimize can only be used by the current user

echo "alias img-optimize=$HOME/.img-optimize/" >> $HOME/.bashrc
source $HOME/.bashrc

Method 2 : Add an alias to the script in /usr/local/bin

With this method img-optimize can be used by all users

sudo ln -s $HOME/.img-optimize/ /usr/local/bin/img-optimize
sudo chmod +x /usr/local/bin/img-optimize


Bash script to optimize your images and convert them in WebP
Usage: img-optimize [options] <images path>
If images path isn't defined, img-optimize will use the current directory
       --jpg <images path> ..... optimize all jpg images
       --png <images path> ..... optimize all png images
       --webp <images path> ..... convert all images in webp
       --nowebp <images path> ..... optimize all png & jpg images
       --all <images path> ..... optimize all images (png + jpg + webp)
       -i, --interactive ..... run img-optimize in interactive mode
       -q, --quiet ..... run image optimization quietly
 Other options :
       -h, --help, help ... displays this help information
  optimize all jpg images in /var/www/images
    img-optimize --jpg /var/www/images

Update the script

To update the script, just run :

git -C $HOME/.img-optimize pull

Setup daily cronjob

You just have to copy the scripts to /etc/cron.daily :

cp $HOME/.img-optimize/crons/ /etc/cron.daily/jpg-png-cron
cp $HOME/.img-optimize/crons/ /etc/cron.daily/webp-cron

chmod +x /etc/cron.daily/jpg-png-cron
chmod +x /etc/cron.daily/webp-cron

Then just edit your websites path set with the variables sites at the beginning of the cron scripts.


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.