0

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

1

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

#!/bin/bash

MY_SHOP_PATH="/path/to/magento"
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
#!/bin/bash
## 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)
    TARGETEXT="(jpg|jpeg|png|gif)"
    EXTENSION="\${FILE##*.}"
  if [[ "\${EXTENSION}" =~ \${TARGETEXT} ]];
    then
   su ${WEB_USER} -s /bin/bash -c "${MY_SHOP_PATH}/wesley.pl \${FILE} > /dev/null"
  fi
done
END

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


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

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.

0

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

https://marketplace.magento.com/

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 you have read our privacy policy.

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