Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active May 11, 2020 08:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save peterjaap/7080989 to your computer and use it in GitHub Desktop.
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
#!/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