Created
March 12, 2020 17:38
-
-
Save leek/951f36dd10eb44eb96b7c64c113f4db8 to your computer and use it in GitHub Desktop.
Magento 2 - Optimize Media
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 | |
if [ ! -f ./app/etc/config.php ]; then | |
echo "-- ERROR" | |
echo "-- This doesn't look like a Magento 2 install. Please make sure" | |
echo "-- that you are running this from the Magento main doc root dir" | |
exit | |
fi | |
echo -ne '\n' | |
echo -ne '░░░░░░░░░░░░░░░░░░░░░░░░░ (0%)\r' | |
find ./pub/media -iname '*.gif' -exec sh -c 'gifsicle -b -O3 -o "{}.out" "{}"; mv "{}.out" "{}"' \; | |
echo -ne '█████░░░░░░░░░░░░░░░░░░░░ (33%)\r' | |
find ./pub/media -iname '*.png' -exec optipng -o5 -keep -preserve '{}' \; | |
echo -ne '██████████░░░░░░░░░░░░░░░ (66%)\r' | |
find ./pub/media -type f -iname '*jpg' -exec sh -c 'jpegtran -outfile "{}.out" -optimize "{}"; mv "{}.out" "{}"' \; | |
echo -ne '█████████████████████████ (100%)\r' | |
echo -ne '\n' | |
echo "Complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment