Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compress every images recursively with options to say quality & root path. Require jpegoptim & optipng
#!/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
#!/bin/bash
for f in $(find $1 -name "*.png")
do
# mogrify $f -resize $2%
optipng -quiet $f
sleep 5
done
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.