Created
March 17, 2017 08:39
-
-
Save Che4ter/434b1f8e4b7133405b94a88d460c49b9 to your computer and use it in GitHub Desktop.
Bulk mozjpeg optimizer on the current directory, works with spaces in filename
This file contains hidden or 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 | |
# Compresses all .jpg/.jpeg and saves them to opt/ | |
# works with spaces in filenames | |
# make sure you adjust the path to mozjpeg bin | |
# uses the mozilla mozjpeg encoder from https://github.com/mozilla/mozjpeg | |
# based on https://gist.github.com/sauramirez/e0ef5059ab637ed3e2cea090b504f385 | |
# Che4ter - 2017 | |
#Change to mozjpeg path | |
MOZJPEG='/opt/mozjpeg/bin/' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
mkdir -p opt | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
shopt -s nullglob | |
for image in *.jpg *.jpeg | |
do | |
printf "${GREEN}Compressing${NC} ${image}\n" | |
${MOZJPEG}djpeg ${image} | ${MOZJPEG}cjpeg -quality 80 | ${MOZJPEG}jpegtran -optimize > opt/${image} | |
done | |
IFS=$SAVEIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm converting multiple images to multiple formats (Avif, WebP, MozJPEG). The following is my file management and I honestly don't want to change it:
The following is what is in the
mozjpeg.sh
:This^ is working just fine.
The only problem is the optimized images are being saved in
parentFolder > outputFolder > inputFolder
. What I want is the optimized images must be saved inparentFolder > outputFolder
.I hope you can help me.