user2700690
user2700690

Reputation: 563

Automate Magento Image Optimization

Is it possible to set up an observer whenever a product image is added, run a shell script to optimize the image or something like that? Maybe it can extend further beyond just product images. Detect new image on the server and run jpegoptim or pngoptim only on the newly added images?

Upvotes: 1

Views: 1281

Answers (2)

Saucier
Saucier

Reputation: 4360

Assuming you are using a Linux based OS and you have enough privileges you could have a look at inotify or fanotify.

I know there exist inotify bindings for Python, Ruby, Haskell and others. There's also a package providing command line tools. And there also exists a inotify based cron daemon.

Also related: How do I program for Linux's new fanotify file system monitoring feature?

Upvotes: 0

MagePal Extensions
MagePal Extensions

Reputation: 17656

In magento, because catalog images are created dynamically from the image uploaded in admin on first page view (catalog list, product detail, etc) using

$this->helper('catalog/image')->init($_product)->resize(163, 100);

it is NOT possible to use any default product observer (like Magento Add New product event observer) to optimizing the images, plus you can always delete all product image using admin (System -> Cache Management).

One possible solution (assuming that you have right access on your server)

  1. Create a bash script that has a cron job that run ever x interval
  2. Check the media folder for all newly created files since last cron job (now-x)
  3. Then optimize them using jpegoptim

Upvotes: 1

Related Questions