Compare commits

...

13 Commits
v2.0 ... master

Author SHA1 Message Date
101b24a5c7 Typo in the question to convert all files to AVIF format
pull from 
https://github.com/VirtuBox/img-optimize/pull/19
2025-01-28 11:00:47 +01:00
ecebc0dadf typo fix 2025-01-28 10:58:38 +01:00
c5fc39d5d1 Preserve metadata when converting to webp
Added to $WEBP_ARGS the '-metadata string all' that copies the metadata from source to webp destination
2025-01-28 10:53:54 +01:00
f8f6188edc optipng already complied for x86_64 2024-07-10 14:30:53 +02:00
27dfe70ce7 Do not change owner when optimizing jpg 2024-04-14 21:47:15 +00:00
8f9c99465a strip-none is not supported by optipng 2023-07-11 13:47:01 +00:00
c3dd0dd535 Keep EXIF data in jpg cron 2023-07-11 13:45:02 +00:00
5fcf709922 Actualizar 'README.md' 2023-07-04 09:11:51 +00:00
8364f01c21 Actualizar 'README.md' 2023-03-13 13:17:41 +00:00
79da33911a Keep all the EXIF/IPTC/etc markers 2023-01-30 09:19:46 +00:00
e39529cd99 Actualizar 'README.md' 2023-01-30 09:16:58 +00:00
VirtuBox
c78ff855ef
Merge pull request #17 from stafyniaksacha/master
Remove lock file on fail
2022-12-02 12:05:32 +01:00
Sacha STAFYNIAK
ae15dcf6b7
Remove lock file on fail 2022-10-20 15:54:37 +02:00
4 changed files with 29 additions and 19 deletions

View File

@ -1,8 +1,10 @@
# Image optimization bash script
![img-optimize](https://raw.githubusercontent.com/VirtuBox/img-optimize/master/img-optimize.png)
![img-optimize](https://gitea.avc.cx/borekon/img-optimize/raw/branch/master/img-optimize.png)
[![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)
The changes from the [original repo](https://github.com/VirtuBox/img-optimize) is that the EXIF data is **preserved**.
All the credits to [VirtuBox](https://github.com/VirtuBox)
## Prerequisite
@ -31,10 +33,10 @@ For Debian/Ubuntu (available in scripts folder) :
```bash
# optipng
curl -sL git.io/fjddn | sudo -E bash
curl -sL https://gitea.avc.cx/borekon/img-optimize/raw/branch/master/scripts/install-optipng.sh | sudo -E bash
# libwebp
curl -sL git.io/fjdd6 | sudo -E bash
curl -sL https://gitea.avc.cx/borekon/img-optimize/raw/branch/master/scripts/install-webp.sh | sudo -E bash
```
### Go-Avif installation
@ -51,7 +53,7 @@ sudo chmod +x /usr/local/bin/avif
1) Clone the repository
```bash
git clone https://github.com/VirtuBox/img-optimize.git $HOME/.img-optimize
git clone https://gitea.avc.cx/borekon/img-optimize.git $HOME/.img-optimize
```
2) Install the script

View File

@ -10,7 +10,7 @@ sites="/var/www/yoursite.tld/images \
for site in $sites; do
# optimize jpg images created in the last 24 hours
find "$site" -ctime 0 -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 jpegoptim --preserve --strip-all -m82 >> /var/log/jpg-png-cron.log 2>&1
find "$site" -ctime 0 -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 jpegoptim --preserve --strip-none -m82 >> /var/log/jpg-png-cron.log 2>&1
# optimize png images created in the last 24 hours
find "$site" -ctime 0 -type f -iname '*.png' -print0 | xargs -0 optipng -o7 -strip all >> /var/log/jpg-png-cron.log 2>&1
find "$site" -ctime 0 -type f -iname '*.png' -print0 | xargs -0 optipng -o7 >> /var/log/jpg-png-cron.log 2>&1
done

View File

@ -16,7 +16,7 @@ CGREEN="${CSI}1;32m"
FIND_ARGS=""
PNG_ARGS=""
JPG_ARGS=""
WEBP_ARGS=""
WEBP_ARGS="-metadata all"
IMG_PATH="$PWD"
_help() {
@ -168,7 +168,7 @@ if [ "$INTERACTIVE_MODE" = "1" ]; then
fi
if [ -z "$AVIF_OPTIMIZATION" ]; then
echo ""
echo "Do you want to convert all jpg & png images to WebP in $IMG_PATH ? (y/n)"
echo "Do you want to convert all jpg & png images to AVIF in $IMG_PATH ? (y/n)"
while [[ $AVIF_OPTIMIZATION != "y" && $AVIF_OPTIMIZATION != "n" ]]; do
echo "Select an option [y/n]: "
read -r AVIF_OPTIMIZATION
@ -186,14 +186,16 @@ fi
if [ "$JPG_OPTIMIZATION" = "y" ]; then
[ -z "$(command -v jpegoptim)" ] && {
echo "Error: jpegoptim isn't installed"
# Free ressource
rm "/tmp/$lock"
exit 1
}
echo -ne ' jpg optimization [..]\r'
cd "$IMG_PATH" || exit 1
if [ -n "$FIND_ARGS" ]; then
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" -p -s --all-progressive -m82
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" -p -P --strip-none --all-progressive -m82
else
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" -p -s -m82 --all-progressive
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -r -0 jpegoptim "$JPG_ARGS" -p -P --strip-none -m82 --all-progressive
fi
echo -ne " jpg optimization [${CGREEN}OK${CEND}]\\r"
@ -202,16 +204,18 @@ fi
if [ "$PNG_OPTIMIZATION" = "y" ]; then
[ -z "$(command -v optipng)" ] && {
echo "Error: optipng isn't installed"
# Free ressource
rm "/tmp/$lock"
exit 1
}
# optimize png
echo -ne ' png optimization [..]\r'
cd "$IMG_PATH" || exit 1
cd "$IMG_PATH" || (rm "/tmp/$lock" && exit 1)
if [ -n "$FIND_ARGS" ]; then
find . -type f -iname '*.png' -cmin "$FIND_ARGS" -print0 | xargs -r -0 optipng "$PNG_ARGS" -o5 -strip all
find . -type f -iname '*.png' -cmin "$FIND_ARGS" -print0 | xargs -r -0 optipng "$PNG_ARGS" -o5
else
find . -type f -iname '*.png' -print0 | xargs -r -0 optipng "$PNG_ARGS" -o5 -strip all
find . -type f -iname '*.png' -print0 | xargs -r -0 optipng "$PNG_ARGS" -o5
fi
echo -ne " png optimization [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
@ -219,11 +223,13 @@ fi
if [ "$WEBP_OPTIMIZATION" = "y" ]; then
[ -z "$(command -v cwebp)" ] && {
echo "Error: cwebp isn't installed"
# Free ressource
rm "/tmp/$lock"
exit 1
}
# convert png to webp
echo -ne ' png to webp conversion [..]\r'
cd "$IMG_PATH" || exit 1
cd "$IMG_PATH" || (rm "/tmp/$lock" && exit 1)
if [ -n "$FIND_ARGS" ]; then
find . -type f -iname "*.png" -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \
bash -c "[ ! -f '{}.webp' ] && { cwebp -z 9 -mt $WEBP_ARGS '{}' -o '{}.webp'; }"
@ -236,7 +242,7 @@ if [ "$WEBP_OPTIMIZATION" = "y" ]; then
# convert jpg to webp
echo -ne ' jpg to webp conversion [..]\r'
cd "$IMG_PATH" || exit 1
cd "$IMG_PATH" || (rm "/tmp/$lock" && 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 '{}.webp' ] && { cwebp $WEBP_ARGS -q 82 -mt '{}' -o '{}.webp || rm -f '{}.webp''; }"
@ -251,11 +257,13 @@ fi
if [ "$AVIF_OPTIMIZATION" = "y" ]; then
[ -z "$(command -v avif)" ] && {
echo "Error: avif isn't installed"
# Free ressource
rm "/tmp/$lock"
exit 1
}
# convert png to avif
echo -ne ' png to avif conversion [..]\r'
cd "$IMG_PATH" || exit 1
cd "$IMG_PATH" || (rm "/tmp/$lock" && 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'; }"
@ -268,7 +276,7 @@ if [ "$AVIF_OPTIMIZATION" = "y" ]; then
# convert jpg to avif
echo -ne ' jpg to avif conversion [..]\r'
cd "$IMG_PATH" || exit 1
cd "$IMG_PATH" || (rm "/tmp/$lock" && 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'; } "
@ -287,4 +295,4 @@ echo -e " ${CGREEN}Image optimization performed successfully !${CEND}"
echo ""
# Free ressource
rm "/tmp/$lock"
rm "/tmp/$lock"

BIN
optipng Normal file

Binary file not shown.