Is there any extension, that can compress the images while uploading as the product image. I have written codes that is used to add products from front end and also using CSV. The users have option upload the images. We would like to compress theses images without loosing quality. I have saw some php codes that can compress the images. But i would like to know if there are any good extensions that can compress product images.

2 Answers 2


if you have server, you can use something like this:


WEB_USER="files owner user name"

yum -y install inotify-tools gifsicle ImageMagick libjpeg-turbo-utils pngcrush

wget -qO ${MY_SHOP_PATH}/wesley.pl https://raw.githubusercontent.com/mikebrittain/Wesley/master/wesley.pl

cat >> ${MY_SHOP_PATH}/images_optimization.sh <<END
## monitor media folder and optimize new images
/usr/bin/inotifywait -e create \\
    -mrq --timefmt %a-%b-%d-%T --format '%w%f %T' \\
    --excludei '\.(xml|php|phtml|html?|css|js|ico|te?mp|txt|csv|swp|sql|t?gz|zip|svn?g|git|log|ini|opt|prog|crush)~?' \\
    ${MY_SHOP_PATH}/media | while read line; do
    echo "\${line} " >> ${MY_SHOP_PATH}/var/log/images_optimization.log
    FILE=\$(echo \${line} | cut -d' ' -f1)
  if [[ "\${EXTENSION}" =~ \${TARGETEXT} ]];
   su ${WEB_USER} -s /bin/bash -c "${MY_SHOP_PATH}/wesley.pl \${FILE} > /dev/null"

echo "${MY_SHOP_PATH}/images_optimization.sh &" >> /etc/rc.local
chmod +x /etc/rc.local

cat >> ${MY_SHOP_PATH}/images_optimization_cron.sh <<END
pgrep images_optimization.sh > /dev/null || ${MY_SHOP_PATH}/images_optimization.sh &

chown ${WEB_USER}:${WEB_USER} ${MY_SHOP_PATH}/images_optimization_cron.sh ${MY_SHOP_PATH}/images_optimization.sh
chmod +x ${MY_SHOP_PATH}/images_optimization_cron.sh ${MY_SHOP_PATH}/images_optimization.sh

crontab -l -u ${WEB_USER} > magecron
echo "*/5 * * * * /bin/bash ${MY_SHOP_PATH}/images_optimization_cron.sh" >> magecron
crontab -u ${WEB_USER} magecron
rm magecron

as you can see this will simply monitor for any new images in the /media folder and optimize it right away. todays cpu power getting very cheap, on average 4-6 cores it will take less than second to check and compress even .png image.


There are lots of image compression extensions on the Magento Marketplace:


Some extensions of note are:

The Nublue Image Optimizer compresses your master images and is simple to use. Specific folders in your Magento library can be targetted for optimisation. Because it compresses your original images, changes are permanent, so test and ensure you're happy with the resulting image quality before running it.

The Apptrian Image Optimizer extension uses a wider range of optimisation tools including Guetzli which creates some of the smallest JPEGs. This extension edits your master images, so again, test the results before running it.

The Sirv CDN & Image Optimizer extension compresses product images and where possible serves them in WebP format (smaller than JPEG). The original images that you uploaded to Magento are kept as master images, then they resized/compressed versions are served to website visitors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.