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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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