• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Image optimization bash script

Image optimization bash script

img-optimize

Travis GitHub GitHub release GitHub last commit Github stars

Prerequisite

  • jpegoptim for jpg optimization
  • optipng for png optimization
  • cwebp for WebP conversion
  • go-avif for Avif 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 git.io/fjddn | sudo -E bash

# libwebp
curl -sL git.io/fjdd6 | sudo -E bash

Go-Avif installation

sudo wget -qO /usr/local/bin/avif https://github.com/Kagami/go-avif/releases/download/v0.1.0/avif-linux-x64
sudo chmod +x /usr/local/bin/avif

Installation

  1. Clone the repository
git clone https://github.com/VirtuBox/img-optimize.git $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/optimize.sh" >> $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/optimize.sh /usr/local/bin/img-optimize
sudo chmod +x /usr/local/bin/img-optimize

Usage

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
  Options:
       --jpg ..... optimize all jpg images
       --png ..... optimize all png images
       --webp ..... convert all images in webp
       --avif ..... convert all images in avif
       --std ..... optimize all png & jpg images
       --next ..... convert all images in webp & avif
       --all ..... optimize all images (png + jpg + webp + avif)
       -i, --interactive ..... run img-optimize in interactive mode
       -q, --quiet ..... run image optimization quietly
       --path <images path> ..... define images path
 Other options :
       -h, --help, help ... displays this help information
       --cmin [+|-]<n> ... File's status was last changed n minutes ago.
         act find cmin argument (+n : greater than n, -n : less than n, n : exactly n)
Examples:
  optimize all jpg images in /var/www/images
    img-optimize --jpg --path /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/jpg-png-cron.sh /etc/cron.daily/jpg-png-cron
cp $HOME/.img-optimize/crons/jpg-png-cron.sh /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.

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

More Repositories

1

nginx-ee

Automated Nginx compilation with HTTP/3 and additional modules support. Compatible with WordOps, EasyEngine & Plesk
Shell
192
star
2

ubuntu-nginx-web-server

EasyEngine/WordOps optimized configuration on Ubuntu 16/18.04 LTS
Shell
108
star
3

advanced-nginx-cheatsheet

Nginx configuration cheatsheet with examples for advanced usage
66
star
4

easyengine-dashboard

A clean bootstrap dashboard for EasyEngine backend
PHP
27
star
5

ee-acme-sh

Bash script to install Let's Encrypt SSL certificates automatically using acme.sh with EasyEngine
Shell
21
star
6

bash-scripts

My own collection of bash scripts
Shell
18
star
7

wo-nginx-setup

Bash script to setup optimized WordOps
Shell
16
star
8

plesk-nginx-fascgi-cache-template

Custom Nginx WordPress VirtualHost template with Nginx fastcgi_cache for Plesk Onyx
PHP
16
star
9

ee-nginx-setup

Bash script to automate optimized EasyEngine v3 setup
Shell
14
star
10

nginx-cloudflare-real-ip

Bash script to restore visitor real IP under Cloudflare with Nginx
Shell
11
star
11

plesk-nginx

Bash script to compile nginx from source with additional modules for Plesk Onyx
Shell
8
star
12

nginx-config

Nginx optimized configurations with examples for some applications
7
star
13

bash-script-template

Bash script template with arguments parsing
Shell
6
star
14

kernel-tweak

Simple systemd service to apply linux kernel tweaks for redis & netdata
Shell
5
star
15

netdata-dashboard

Custom netdata dashboard built with bootstrap 4 - demo https://virtubox.net/netdata
HTML
4
star
16

ubuntu-plesk-onyx

Plesk Onyx custom configuration on Ubuntu 16.04 LTS
4
star
17

awesome-stars

A curated list of my GitHub stars!
3
star
18

EngineScript

EngineScript - Automated WordPress LEMP Server on Ubuntu
Shell
2
star
19

my-awesome-stars

A curated list of my GitHub stars!
1
star