Compress every images recursively with options to say quality & root path. Also converts every images to webp. Requires jpegoptim, optipng & cwebp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for f in `find $1 -name "*.jpg"` | |
do | |
# mogrify $f -resize $2% | |
jpegoptim --all-progressive -q -m$2 $f | |
sleep 4 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for f in $(find $1 -name "*.png") | |
do | |
# mogrify $f -resize $2% | |
optipng -quiet $f | |
sleep 5 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |