Last active
May 11, 2020 08:28
-
-
Save peterjaap/7080989 to your computer and use it in GitHub Desktop.
Convert images to smaller size and lower quality to reduce file sizes for Magento's original product photos
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 | |
# convertImages.sh | |
# Author: Peter Jaap Blaakmeer (elgentos.nl) | |
# https://gist.github.com/peterjaap/7080989 | |
NEWQUALITY=80 | |
NEWSIZE=1000 | |
DIRECTORY=media/catalog/product/ | |
du -hs $DIRECTORY | |
for f in $(find $DIRECTORY -type f); | |
do | |
WIDTH=`identify -format '%w' $f | tr -d "\r\n"`; | |
if [ $WIDTH -gt $NEWSIZE ]; then | |
SIZEBEFORE=`ls -lah $f | awk '{ print $5}'`; | |
convert $f -resize $NEWSIZE -quality $NEWQUALITY $f; | |
SIZEAFTER=`ls -lah $f | awk '{ print $5}'`; | |
echo "$f has been converted - from ${SIZEBEFORE} to ${SIZEAFTER}"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment