Allows to process product and other images with third-party image manipulation tools.
This event is triggered every time when you call the
Db_File::getThumbnailPath() method,
and hence - every time when you call the
Shop_Product::image_url() and
Shop_Category::image_url() methods.
Thus the event allows to use the usual programming interface with third-party image processing modules.
The event handler should return a path to the generated image. The path should be relative to the LemonStand root directory.
In the event handler you should check whether the thumbnail is not generated yet. Example of the event handler:
public function subscribeEvents()
{
Backend::$events->addEvent('core:onProcessImage', $this, 'process_image');
}
public function process_image($file_obj, $width, $height, $returnJpeg, $params)
{
// This handler just copies the original image to the uploaded/thumbnails directory
//
// Generate the thumbnail file name and check whether it does not exist yet
$ext = $returnJpeg ? 'jpg' : 'png';
$thumbnail_path = '/uploaded/thumbnails/db_file_img_'.$file_obj->id.'_'.$width.'x'.$height.'.'.$ext;
// Return the thumbnail path if it does exist
if (file_exists($thumbnail_path))
return $thumbnail_path;
// Process image with a third-party image library and save it to the
// uploaded/thumbnails directory. Please note - to get an absolute path
// to a file, we prepend the PATH_APP constant.
copy(PATH_APP.$file_obj->getPath(), PATH_APP.$thumbnail_path);
// Return the relative path to the thumbnail
return $thumbnail_path;
}