Merge pull request #15 from VirtuBox/develop

v2.0
This commit is contained in:
VirtuBox 2020-11-11 13:38:51 +01:00 committed by GitHub
commit 6c8104ca2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 450 additions and 259 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

39
.gitattributes vendored Normal file
View File

@ -0,0 +1,39 @@
# Auto detect text files and perform LF normalization
* text=auto
# Documents
*.md text eol=lf
*.tex text diff=tex
*.adoc text
*.textile text
*.mustache text eol=lf
*.csv text
*.tab text
*.tsv text
*.txt text
*.sql text
# Scripts
*.bash text eol=lf
*.fish text eol=lf
*.sh text eol=lf
# Source files
# ============
*.pxd text diff=python
*.py text diff=python
*.py3 text diff=python
*.pyc text diff=python
*.pyd text diff=python
*.pyo text diff=python
*.pyw text diff=python
*.pyx text diff=python
*.pyz text diff=python
#
# Exclude files from exporting
#
.gitattributes export-ignore
.gitignore export-ignore

49
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,49 @@
name: CI
on:
push:
branches:
- develop
- master
pull_request:
branches:
- master
release:
types: [published]
schedule:
- cron: '0 0 * * 0'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a set of commands using the runners shell
- name: Install prerequesites
run: |
sudo apt-get update
sudo apt-get install jpegoptim -y
sudo -E time bash scripts/install-webp.sh > /dev/null 2>&1
sudo -E time bash scripts/install-optipng.sh > /dev/null 2>&1
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
sudo cp optimize.sh /usr/local/bin/img-optimize
sudo chmod 755 /usr/local/bin/img-optimize
- name: Optimize Images
run: |
ls -alh images/
/usr/local/bin/img-optimize --avif
ls -alh images/
/usr/local/bin/img-optimize --webp
ls -alh images/
rm -f images/*.webp images/*.avif
/usr/local/bin/img-optimize --all
ls -alh images/

View File

@ -1,7 +1,7 @@
sudo: required os: linux
dist: bionic dist: bionic
language: bash language: shell
cache: cache:
apt: true apt: true
@ -10,6 +10,7 @@ git:
quiet: true quiet: true
before_script: before_script:
- sudo apt-get install tree -y
- sudo apt-get -qq autoremove --purge - sudo apt-get -qq autoremove --purge
addons: addons:
apt: apt:
@ -17,14 +18,19 @@ addons:
script: script:
- sudo apt-get install jpegoptim -y - sudo apt-get install jpegoptim -y
- sudo bash scripts/install-webp.sh - sudo -E time bash scripts/install-webp.sh > /dev/null 2>&1
- sudo bash scripts/install-optipng.sh - sudo -E time bash scripts/install-optipng.sh > /dev/null 2>&1
- 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
- sudo cp optimize.sh /usr/local/bin/img-optimize - sudo cp optimize.sh /usr/local/bin/img-optimize
- sudo chmod 755 /usr/local/bin/img-optimize - sudo chmod 755 /usr/local/bin/img-optimize
- /usr/local/bin/img-optimize --all - ls -alh images/
- /usr/local/bin/img-optimize -jpg -q - /usr/local/bin/img-optimize --all -q
- ls -alh images/
- /usr/local/bin/img-optimize --jpg -q
- /usr/local/bin/img-optimize --png -q - /usr/local/bin/img-optimize --png -q
- rm images/*.webp - rm images/*.webp
- /usr/local/bin/img-optimize --webp - /usr/local/bin/img-optimize --webp
- tree -L 2 .
- rm images/*.webp - rm images/*.webp
- /usr/local/bin/img-optimize --webp --quiet - /usr/local/bin/img-optimize --webp --quiet

View File

@ -6,14 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased] ## [Unreleased]
## [V2.0] - 2020-11-10
### Added ### Added
- quiet mode - quiet mode
- option --no-run-if-empty added to xargs - option --no-run-if-empty added to xargs
- scripts to compile optipng & libwebp from source - scripts to compile optipng & libwebp from source
- Avif (AV1 Image Format) support
- Avoid optimizing the same image at the same moment [PR #12](https://github.com/VirtuBox/img-optimize/pull/12)
### Changed ### Changed
- JPG are optimized as progressive JPG
- WebP and Avif newly created images are deleted in case of failure during conversion
## [V1.1] - 2019-04-05 ## [V1.1] - 2019-04-05
### Added ### Added

253
README.md
View File

@ -1,120 +1,133 @@
# 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
- go-avif for Avif conversion
### From APT repositories
### From APT repositories
Debian/Ubuntu :
Debian/Ubuntu :
```bash
sudo apt install jpegoptim optipng webp -y ```bash
``` sudo apt install jpegoptim optipng webp -y
```
Centos 7 :
Centos 7 :
```bash
sudo yum install optipng jpegoptim libwebp-tools -y ```bash
``` 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
# optipng ```bash
curl -sL git.io/fjddn | sudo -E bash # optipng
curl -sL git.io/fjddn | sudo -E bash
# libwebp
curl -sL git.io/fjdd6 | sudo -E bash # libwebp
``` curl -sL git.io/fjdd6 | sudo -E bash
```
--------------------------------------------------------------------------------
### Go-Avif installation
## Installation
```bash
1) Clone the repository 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
```bash ```
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
``` --------------------------------------------------------------------------------
2) Install the script ## Installation
**Method 1** : Add an alias in .bashrc 1) Clone the repository
With this method img-optimize can only be used by the current user ```bash
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
```bash ```
echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc
source $HOME/.bashrc 2) Install the script
```
**Method 1** : Add an alias in .bashrc
**Method 2** : Add an alias to the script in /usr/local/bin
With this method img-optimize can only be used by the current user
With this method img-optimize can be used by all users
```bash
```bash echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc
sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize source $HOME/.bashrc
sudo chmod +x /usr/local/bin/img-optimize ```
```
**Method 2** : Add an alias to the script in /usr/local/bin
## Usage
With this method img-optimize can be used by all users
```bash
Bash script to optimize your images and convert them in WebP ```bash
Usage: img-optimize [options] <images path> sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize
If images path isn't defined, img-optimize will use the current directory sudo chmod +x /usr/local/bin/img-optimize
Options: ```
--jpg <images path> ..... optimize all jpg images
--png <images path> ..... optimize all png images ## Usage
--webp <images path> ..... convert all images in webp
--nowebp <images path> ..... optimize all png & jpg images ```bash
--all <images path> ..... optimize all images (png + jpg + webp) Bash script to optimize your images and convert them in WebP
-i, --interactive ..... run img-optimize in interactive mode Usage: img-optimize [options] <images path>
-q, --quiet ..... run image optimization quietly If images path isn't defined, img-optimize will use the current directory
Other options : Options:
-h, --help, help ... displays this help information --jpg ..... optimize all jpg images
Examples: --png ..... optimize all png images
optimize all jpg images in /var/www/images --webp ..... convert all images in webp
img-optimize --jpg /var/www/images --avif ..... convert all images in avif
``` --std ..... optimize all png & jpg images
--next ..... convert all images in webp & avif
## Update the script --all ..... optimize all images (png + jpg + webp + avif)
-i, --interactive ..... run img-optimize in interactive mode
To update the script, just run : -q, --quiet ..... run image optimization quietly
--path <images path> ..... define images path
```bash Other options :
git -C $HOME/.img-optimize pull -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)
## Setup daily cronjob Examples:
optimize all jpg images in /var/www/images
You just have to copy the scripts to /etc/cron.daily : img-optimize --jpg --path /var/www/images
```
```bash
cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/jpg-png-cron ### Update the script
cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/webp-cron
To update the script, just run :
chmod +x /etc/cron.daily/jpg-png-cron
chmod +x /etc/cron.daily/webp-cron ```bash
``` git -C $HOME/.img-optimize pull
```
Then just edit your websites path set with the variables `sites` at the beginning of the cron scripts.
### Setup daily cronjob
## Warning
You just have to copy the scripts to /etc/cron.daily :
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.
```bash
## Credits 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
- 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)
chmod +x /etc/cron.daily/jpg-png-cron
- Tutorial about webp conversion available on [jesuisadmin.fr](https://jesuisadmin.fr/convertir-vos-images-en-webp-nginx/) (in french) 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
- 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)

View File

@ -1,120 +1,133 @@
# 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
- go-avif for Avif conversion
### From APT repositories
### From APT repositories
Debian/Ubuntu :
Debian/Ubuntu :
```bash
sudo apt install jpegoptim optipng webp -y ```bash
``` sudo apt install jpegoptim optipng webp -y
```
Centos 7 :
Centos 7 :
```bash
sudo yum install optipng jpegoptim libwebp-tools -y ```bash
``` 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
# optipng ```bash
curl -sL git.io/fjddn | sudo -E bash # optipng
curl -sL git.io/fjddn | sudo -E bash
# libwebp
curl -sL git.io/fjdd6 | sudo -E bash # libwebp
``` curl -sL git.io/fjdd6 | sudo -E bash
```
--------------------------------------------------------------------------------
### Go-Avif installation
## Installation
```bash
1) Clone the repository 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
```bash ```
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
``` --------------------------------------------------------------------------------
2) Install the script ## Installation
**Method 1** : Add an alias in .bashrc 1) Clone the repository
With this method img-optimize can only be used by the current user ```bash
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
```bash ```
echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc
source $HOME/.bashrc 2) Install the script
```
**Method 1** : Add an alias in .bashrc
**Method 2** : Add an alias to the script in /usr/local/bin
With this method img-optimize can only be used by the current user
With this method img-optimize can be used by all users
```bash
```bash echo "alias img-optimize=$HOME/.img-optimize/optimize.sh" >> $HOME/.bashrc
sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize source $HOME/.bashrc
sudo chmod +x /usr/local/bin/img-optimize ```
```
**Method 2** : Add an alias to the script in /usr/local/bin
## Usage
With this method img-optimize can be used by all users
```bash
Bash script to optimize your images and convert them in WebP ```bash
Usage: img-optimize [options] <images path> sudo ln -s $HOME/.img-optimize/optimize.sh /usr/local/bin/img-optimize
If images path isn't defined, img-optimize will use the current directory sudo chmod +x /usr/local/bin/img-optimize
Options: ```
--jpg <images path> ..... optimize all jpg images
--png <images path> ..... optimize all png images ## Usage
--webp <images path> ..... convert all images in webp
--nowebp <images path> ..... optimize all png & jpg images ```bash
--all <images path> ..... optimize all images (png + jpg + webp) Bash script to optimize your images and convert them in WebP
-i, --interactive ..... run img-optimize in interactive mode Usage: img-optimize [options] <images path>
-q, --quiet ..... run image optimization quietly If images path isn't defined, img-optimize will use the current directory
Other options : Options:
-h, --help, help ... displays this help information --jpg ..... optimize all jpg images
Examples: --png ..... optimize all png images
optimize all jpg images in /var/www/images --webp ..... convert all images in webp
img-optimize --jpg /var/www/images --avif ..... convert all images in avif
``` --std ..... optimize all png & jpg images
--next ..... convert all images in webp & avif
## Update the script --all ..... optimize all images (png + jpg + webp + avif)
-i, --interactive ..... run img-optimize in interactive mode
To update the script, just run : -q, --quiet ..... run image optimization quietly
--path <images path> ..... define images path
```bash Other options :
git -C $HOME/.img-optimize pull -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)
## Setup daily cronjob Examples:
optimize all jpg images in /var/www/images
You just have to copy the scripts to /etc/cron.daily : img-optimize --jpg --path /var/www/images
```
```bash
cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/jpg-png-cron ### Update the script
cp $HOME/.img-optimize/crons/jpg-png-cron.sh /etc/cron.daily/webp-cron
To update the script, just run :
chmod +x /etc/cron.daily/jpg-png-cron
chmod +x /etc/cron.daily/webp-cron ```bash
``` git -C $HOME/.img-optimize pull
```
Then just edit your websites path set with the variables `sites` at the beginning of the cron scripts.
### Setup daily cronjob
## Warning
You just have to copy the scripts to /etc/cron.daily :
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.
```bash
## Credits 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
- 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)
chmod +x /etc/cron.daily/jpg-png-cron
- Tutorial about webp conversion available on [jesuisadmin.fr](https://jesuisadmin.fr/convertir-vos-images-en-webp-nginx/) (in french) 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
- 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)

View File

@ -7,7 +7,7 @@
# Author: VirtuBox # Author: VirtuBox
# License: M.I.T # License: M.I.T
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Version 1.1 - 2019-07-12 # Version 2.0 - 2020-11-10
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
CSI='\033[' CSI='\033['
@ -27,8 +27,10 @@ _help() {
echo " --jpg ..... optimize all jpg images" echo " --jpg ..... optimize all jpg images"
echo " --png ..... optimize all png images" echo " --png ..... optimize all png images"
echo " --webp ..... convert all images in webp" echo " --webp ..... convert all images in webp"
echo " --nowebp ..... optimize all png & jpg images" echo " --avif ..... convert all images in avif"
echo " --all ..... optimize all images (png + jpg + webp)" echo " --std ..... optimize all png & jpg images"
echo " --next ..... convert all images in webp & avif"
echo " --all ..... optimize all images (png + jpg + webp + avif)"
echo " -i, --interactive ..... run img-optimize in interactive mode" echo " -i, --interactive ..... run img-optimize in interactive mode"
echo " -q, --quiet ..... run image optimization quietly" echo " -q, --quiet ..... run image optimization quietly"
echo " --path <images path> ..... define images path" echo " --path <images path> ..... define images path"
@ -60,18 +62,27 @@ else
--png) --png)
PNG_OPTIMIZATION="y" PNG_OPTIMIZATION="y"
;; ;;
--nowebp) --std)
JPG_OPTIMIZATION="y" JPG_OPTIMIZATION="y"
PNG_OPTIMIZATION="y" PNG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="n" WEBP_OPTIMIZATION="n"
AVIF_OPTIMIZATION="n"
;;
--next)
AVIF_OPTIMIZATION="y"
WEBP_OPTIMIZATION="y"
;; ;;
--webp) --webp)
WEBP_OPTIMIZATION="y" WEBP_OPTIMIZATION="y"
;; ;;
--avif)
AVIF_OPTIMIZATION="y"
;;
--all) --all)
PNG_OPTIMIZATION="y" PNG_OPTIMIZATION="y"
JPG_OPTIMIZATION="y" JPG_OPTIMIZATION="y"
WEBP_OPTIMIZATION="y" WEBP_OPTIMIZATION="y"
AVIF_OPTIMIZATION="y"
;; ;;
-i | --interactive) -i | --interactive)
INTERACTIVE_MODE="1" INTERACTIVE_MODE="1"
@ -155,6 +166,16 @@ if [ "$INTERACTIVE_MODE" = "1" ]; then
echo "" echo ""
echo "" echo ""
fi fi
if [ -z "$AVIF_OPTIMIZATION" ]; then
echo ""
echo "Do you want to convert all jpg & png images to WebP in $IMG_PATH ? (y/n)"
while [[ $AVIF_OPTIMIZATION != "y" && $AVIF_OPTIMIZATION != "n" ]]; do
echo "Select an option [y/n]: "
read -r AVIF_OPTIMIZATION
done
echo ""
echo ""
fi
fi fi
################################## ##################################
@ -170,9 +191,9 @@ if [ "$JPG_OPTIMIZATION" = "y" ]; then
echo -ne ' jpg optimization [..]\r' echo -ne ' jpg optimization [..]\r'
cd "$IMG_PATH" || exit 1 cd "$IMG_PATH" || exit 1
if [ -n "$FIND_ARGS" ]; then if [ -n "$FIND_ARGS" ]; then
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" --preserve --strip-all -m82 find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" -p -s --all-progressive -m82
else else
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" --preserve --strip-all -m82 find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" -p -s -m82 --all-progressive
fi fi
echo -ne " jpg optimization [${CGREEN}OK${CEND}]\\r" echo -ne " jpg optimization [${CGREEN}OK${CEND}]\\r"
@ -205,10 +226,10 @@ if [ "$WEBP_OPTIMIZATION" = "y" ]; then
cd "$IMG_PATH" || exit 1 cd "$IMG_PATH" || exit 1
if [ -n "$FIND_ARGS" ]; then if [ -n "$FIND_ARGS" ]; then
find . -type f -iname "*.png" -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \ find . -type f -iname "*.png" -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \
bash -c '[ ! -f "{}.webp" ] && { cwebp -z 9 -mt -quiet "{}" -o "{}.webp"; }' bash -c "[ ! -f '{}.webp' ] && { cwebp -z 9 -mt $WEBP_ARGS '{}' -o '{}.webp'; }"
else else
find . -type f -iname "*.png" -print0 | xargs -0 -r -I {} \ find . -type f -iname "*.png" -print0 | xargs -0 -r -I {} \
bash -c '[ ! -f "{}.webp" ] && { cwebp -z 9 -mt -quiet "{}" -o "{}.webp"; }' bash -c "[ ! -f '{}.webp' ] && { cwebp -z 9 -mt $WEBP_ARGS '{}' -o '{}.webp'; }"
fi fi
echo -ne " png to webp conversion [${CGREEN}OK${CEND}]\\r" echo -ne " png to webp conversion [${CGREEN}OK${CEND}]\\r"
echo -ne '\n' echo -ne '\n'
@ -218,15 +239,47 @@ if [ "$WEBP_OPTIMIZATION" = "y" ]; then
cd "$IMG_PATH" || exit 1 cd "$IMG_PATH" || exit 1
if [ -n "$FIND_ARGS" ]; then if [ -n "$FIND_ARGS" ]; then
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \ find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \
bash -c '[ ! -f "{}.webp" ] && { cwebp -quiet -q 82 -mt "{}" -o "{}.webp"; }' bash -c "[ ! -f '{}.webp' ] && { cwebp $WEBP_ARGS -q 82 -mt '{}' -o '{}.webp || rm -f '{}.webp''; }"
else else
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 -r -I {} \ find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 -r -I {} \
bash -c '[ ! -f "{}.webp" ] && { cwebp -quiet -q 82 -mt "{}" -o "{}.webp"; }' bash -c "[ ! -f '{}.webp' ] && { cwebp $WEBP_ARGS -q 82 -mt '{}' -o '{}.webp' || rm -f '{}.webp'; }"
fi fi
echo -ne " jpg to webp conversion [${CGREEN}OK${CEND}]\\r" echo -ne " jpg to webp conversion [${CGREEN}OK${CEND}]\\r"
echo -ne '\n' echo -ne '\n'
fi fi
if [ "$AVIF_OPTIMIZATION" = "y" ]; then
[ -z "$(command -v avif)" ] && {
echo "Error: avif isn't installed"
exit 1
}
# convert png to avif
echo -ne ' png to avif conversion [..]\r'
cd "$IMG_PATH" || exit 1
if [ -n "$FIND_ARGS" ]; then
find . -type f -iname "*.png" -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \
bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif' || rm -f '{}.avif'; }"
else
find . -type f -iname "*.png" -print0 | xargs -0 -r -I {} \
bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif' || rm -f '{}.avif'; }"
fi
echo -ne " png to avif conversion [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
# convert jpg to avif
echo -ne ' jpg to avif conversion [..]\r'
cd "$IMG_PATH" || exit 1
if [ -n "$FIND_ARGS" ]; then
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \
bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif' || rm -f '{}.avif'; } "
else
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 -r -I {} \
bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif' || rm -f '{}.avif'; }"
fi
echo -ne " jpg to avif conversion [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
fi
# We're done ! # We're done !
echo "" echo ""

View File

@ -24,7 +24,8 @@ curl -sL "$OPTIPNGLATEST" | tar -I pigz -xf -
cd optipng-* || exit 1 cd optipng-* || exit 1
# configure and compile optipng # configure and compile optipng
./configure --prefix=/usr ./configure
make -j "$(nproc)" make -j "$(nproc)"
strip --strip-unneeded /usr/local/src/optipng-*/src/optipng/optipng strip --strip-unneeded /usr/local/src/optipng-*/src/optipng/optipng
make install make install
ldconfig

View File

@ -24,7 +24,8 @@ curl -sL "https:$LATEST_WEBP" | tar -I pigz -xf -
cd libwebp-* || exit cd libwebp-* || exit
# configure libwebp and launch compilation # configure libwebp and launch compilation
./configure --prefix=/usr ./configure
make -j "$(nproc)" make -j "$(nproc)"
strip --strip-unneeded /usr/local/src/libwebp-*/examples/.libs/{cwebp,dwebp} strip --strip-unneeded /usr/local/src/libwebp-*/examples/.libs/{cwebp,dwebp}
make install make install
ldconfig