update readme

This commit is contained in:
VirtuBox 2019-12-08 14:52:02 +01:00
parent 54457264a4
commit 1b458c423c
No known key found for this signature in database
GPG Key ID: 22EB296C97BAD476

240
README.md
View File

@ -1,120 +1,120 @@
# Image optimization bash script # Image optimization bash script
![img-optimize](https://raw.githubusercontent.com/VirtuBox/img-optimize/master/img-optimize.png) ![img-optimize](https://raw.githubusercontent.com/VirtuBox/img-optimize/master/img-optimize.png)
[![Travis](https://img.shields.io/travis/virtubox/img-optimize.svg)](https://travis-ci.org/VirtuBox/img-optimize) ![GitHub](https://img.shields.io/github/license/VirtuBox/img-optimize.svg) ![GitHub release](https://img.shields.io/github/release/VirtuBox/img-optimize.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/VirtuBox/img-optimize.svg) ![Github stars](https://img.shields.io/github/stars/VirtuBox/img-optimize.svg) [![Travis](https://travis-ci.org/VirtuBox/img-optimize.svg?branch=master)](https://travis-ci.org/VirtuBox/img-optimize) ![GitHub](https://img.shields.io/github/license/VirtuBox/img-optimize.svg) ![GitHub release](https://img.shields.io/github/release/VirtuBox/img-optimize.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/VirtuBox/img-optimize.svg) ![Github stars](https://img.shields.io/github/stars/VirtuBox/img-optimize.svg)
## Prerequisite ## Prerequisite
- jpegoptim for jpg optimization - jpegoptim for jpg optimization
- optipng for png optimization - optipng for png optimization
- cwebp for WebP conversion - cwebp for WebP conversion
### From APT repositories ### From APT repositories
Debian/Ubuntu : Debian/Ubuntu :
```bash ```bash
sudo apt install jpegoptim optipng webp -y sudo apt install jpegoptim optipng webp -y
``` ```
Centos 7 : Centos 7 :
```bash ```bash
sudo yum install optipng jpegoptim libwebp-tools -y sudo yum install optipng jpegoptim libwebp-tools -y
``` ```
### Compile the latest release (optipng & libwebp) ### Compile the latest release (optipng & libwebp)
For Debian/Ubuntu (available in scripts folder) : For Debian/Ubuntu (available in scripts folder) :
```bash ```bash
# optipng # optipng
curl -sL git.io/fjddn | sudo -E bash curl -sL git.io/fjddn | sudo -E bash
# libwebp # libwebp
curl -sL git.io/fjdd6 | sudo -E bash curl -sL git.io/fjdd6 | sudo -E bash
``` ```
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
## Installation ## Installation
1) Clone the repository 1) Clone the repository
```bash ```bash
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
``` ```
2) Install the script 2) Install the script
**Method 1** : Add an alias in .bashrc **Method 1** : Add an alias in .bashrc
With this method img-optimize can only be used by the current user With this method img-optimize can only be used by the current user
```bash ```bash
echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc
source $HOME/.bashrc source $HOME/.bashrc
``` ```
**Method 2** : Add an alias to the script in /usr/local/bin **Method 2** : Add an alias to the script in /usr/local/bin
With this method img-optimize can be used by all users With this method img-optimize can be used by all users
```bash ```bash
sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize
sudo chmod +x /usr/local/bin/img-optimize sudo chmod +x /usr/local/bin/img-optimize
``` ```
## Usage ## Usage
```bash ```bash
Bash script to optimize your images and convert them in WebP Bash script to optimize your images and convert them in WebP
Usage: img-optimize [options] <images path> Usage: img-optimize [options] <images path>
If images path isn't defined, img-optimize will use the current directory If images path isn't defined, img-optimize will use the current directory
Options: Options:
--jpg <images path> ..... optimize all jpg images --jpg <images path> ..... optimize all jpg images
--png <images path> ..... optimize all png images --png <images path> ..... optimize all png images
--webp <images path> ..... convert all images in webp --webp <images path> ..... convert all images in webp
--nowebp <images path> ..... optimize all png & jpg images --nowebp <images path> ..... optimize all png & jpg images
--all <images path> ..... optimize all images (png + jpg + webp) --all <images path> ..... optimize all images (png + jpg + webp)
-i, --interactive ..... run img-optimize in interactive mode -i, --interactive ..... run img-optimize in interactive mode
-q, --quiet ..... run image optimization quietly -q, --quiet ..... run image optimization quietly
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
To update the script, just run : To update the script, just run :
```bash ```bash
git -C $HOME/.img-optimize pull git -C $HOME/.img-optimize pull
``` ```
## Setup daily cronjob ## Setup daily cronjob
You just have to copy the scripts to /etc/cron.daily : You just have to copy the scripts to /etc/cron.daily :
```bash ```bash
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/jpg-png-cron
cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/webp-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/jpg-png-cron
chmod +x /etc/cron.daily/webp-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. Then just edit your websites path set with the variables `sites` at the beginning of the cron scripts.
## Warning ## 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. 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 ## Credits
- WebP conversion script was inspired by this [DigitalOcean Community Tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website) - WebP conversion script was inspired by this [DigitalOcean Community Tutorial](https://www.digitalocean.com/community/tutorials/how-to-create-and-serve-webp-images-to-speed-up-your-website)
- Tutorial about webp conversion available on [jesuisadmin.fr](https://jesuisadmin.fr/convertir-vos-images-en-webp-nginx/) (in french) - Tutorial about webp conversion available on [jesuisadmin.fr](https://jesuisadmin.fr/convertir-vos-images-en-webp-nginx/) (in french)