Compress images script

Compress every images recursively with options to say quality & root path. Also converts every images to webp. Requires jpegoptim, optipng & cwebp 

#!/bin/bash
usage()
{
echo "Usage: sh images_compress.sh -d /directory -q 60"
exit
}
while [ "$1" != "" ]; do
case $1 in
-d ) shift
DIRECTORY=$1
;;
-q ) shift
QUALITY=$1
;;
* ) QUERY=$1
esac
shift
done
TAILLE=$(du -hs $DIRECTORY)
wait
echo "Avant : "$TAILLE
sh ./webp_compress.sh $DIRECTORY $QUALITY
sh ./jpg_compress.sh $DIRECTORY $QUALITY &
sh ./png_compress.sh $DIRECTORY $QUALITY &
wait
echo "fini !"
echo "Avant : "$TAILLE
echo "Apres : " && du -hs $DIRECTORY
#!/bin/bash
for f in `find $1 -name "*.jpg"`
do
# mogrify $f -resize $2%
jpegoptim --all-progressive -q -m$2 $f
sleep 4
done
view raw jpg_compress.sh hosted with ❤ by GitHub
#!/bin/bash
for f in $(find $1 -name "*.png")
do
# mogrify $f -resize $2%
optipng -quiet $f
sleep 5
done
view raw png_compress.sh hosted with ❤ by GitHub
#!/bin/bash
for f in $(find $1 -name "*.png")
do
cwebp -quiet -q $2 -m 6 $f -o $f.webp
sleep 5
done
for f in $(find $1 -name "*.jpg")
do
cwebp -quiet -q $2 -m 6 $f -o $f.webp
sleep 5
done

Laissez un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors