This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

core:onProcessImage event

Triggered by Db_File
Author LemonStand eCommerce Inc.

Event handler signature

public string event_onProcessImage(Db_File $file, mixed $width, mixed $height, boolean $as_jpeg, array $params)
$file Db_File specifies the original file object.
$width mixed the image width requested in the Db_File::getThumbnailPath() method call.
$height mixed the image height requested in the Db_File::getThumbnailPath() method call.
$as_jpeg boolean determines whether JPEG or PNG image will be created.
$params array specifies the $params parameter value specified in the Db_File::getThumbnailPath() method call. You can use this parameter for passing image library specific parameters from the Db_File::getThumbnailPath() call to the event handler.
{return} string returns path to the generated image.
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;
}