update script

This commit is contained in:
VirtuBox 2018-07-28 15:55:27 +02:00
parent 1b8a2c4f47
commit 584d07beed
4 changed files with 70 additions and 34 deletions

View File

@ -1,19 +1,54 @@
# WP-optimize
## Bash script to optimize your images and convert them in WebP
### What does the script do ?
### Prerequisite
- install jpegoptim and optipng
- optimize all your images in /var/www
* jpegoptim
* optipng
* WebP
To run the script :
Debian/Ubuntu :
```bash
sudo apt install jpegoptim optipng webp -y
```
#For debian/Ubuntu
bash <(wget --no-check-certificate -O - https://raw.githubusercontent.com/VirtuBox/wp-optimize/master/deb-optimize.sh)
wget -qO optimize.sh
#For Centos/RedHat
cd /var/www
bash <(wget --no-check-certificate -O - https://raw.githubusercontent.com/VirtuBox/wp-optimize/master/centos-optimize.sh)
Centos 7 :
```bash
sudo yum install optipng jpegoptim libwebp-tools -y
```
### What does the script do
1) optimize jpg images with jpegoptim
2) optimize png images with optipng
3) convert jpg & png images in WebP (without deleting them)
WebP image name example for mybackground.png : mybackground.png.webp
---
### Usage
1) Download the script and make it executable
```bash
wget https://raw.githubusercontent.com/VirtuBox/wp-optimize/master/optimize.sh
chmod +x optimize.sh
```
2) Launch the script and set the path of your images as first argument
```bash
./optimize.sh /path/to/your/images
```
To avoid permissions issues, you can run the script with another user with sudo
```bash
sudo -u www-data ./optimize.sh /path/to/your/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.

View File

@ -1,11 +0,0 @@
#!/bin/bash
echo ""
echo "Welcome to wp-optimize script"
echo ""
yum update &>/dev/null
yum install optipng jpegoptim -y &>/dev/null
find . -name *.jp* | xargs jpegoptim --strip-all -m76
find . -iname '*.png' -print0 | xargs -0 optipng -o7 -preserve
echo ""
echo "Optimization Process done :)"
echo ""

View File

@ -1,12 +0,0 @@
#!/bin/bash
echo ""
echo "Welcome to wp-optimize script"
echo ""
apt-get update &>/dev/null
apt-get install optipng jpegoptim -y &>/dev/null
cd /var/www
find . -name *.jp* | xargs jpegoptim --strip-all -m76
find . -iname '*.png' -print0 | xargs -0 optipng -o7 -preserve
echo ""
echo "Optimization Process done :)"
echo ""

24
optimize.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# optimize jpg
find "$1" -iname "*.jp*" -print0 | xargs -0 jpegoptim --strip-all -m76
# optimize png
find "$1" -iname '*.png' -print0 | xargs -0 optipng -o7 -preserve
# convert png to webp
find "$1" -iname "*.png" -print0 | xargs -0 -I {} \
bash -c '
webp_version="$0".webp
if [ ! -f "$webp_version" ]; then
{ cwebp -lossless {} -o {}.webp; }
fi'
# convert jpg to webp
find "$1" -iname "*.jp*" -print0 | xargs -0 -I {} \
bash -c '
webp_version="$0".webp
if [ ! -f "$webp_version" ]; then
{ cwebp -lossless {} -o {}.webp; }
fi'