Created
November 28, 2023 17:22
-
-
Save greg-randall/e25a29b567155974e7020e12771da944 to your computer and use it in GitHub Desktop.
Compress jpgs with MozJpeg recursively.
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 | |
#convert pngs to jpg | |
#find . -type d -exec bash -c 'cd "{}" && mogrify -format jpg *.png' \; | |
#find . -type f -name '*.png' -delete | |
#convert gifs to jpg | |
#find . -type d -exec bash -c 'cd "{}" && mogrify -format jpg *.gif' \; | |
#find . -type f -name '*.gif' -delete | |
#rename jpeg to jpg | |
#find . -type f -iname "*.jpeg" -exec bash -c 'mv "$0" "${0%.jpeg}.jpg"' {} \; | |
#find . -type f -iname "*.jpeg" -exec bash -c 'mv "$0" "${0%.JPEG}.jpg"' {} \; | |
echo "optimizing jpgs" | |
shopt -s globstar | |
for file in **/*.jpg | |
do | |
echo "Processing $file" | |
mozjpeg "$file" > "temp.jpg" | |
mozjpegtran "temp.jpg" > "$file" | |
done | |
rm "temp.jpg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment