You are here

function canvasactions_imagemask_image in ImageCache Actions 6.2

Apply the given image file to the canvas as a mask

Implementation of hook_image()

Parameters

$image:

$action:

File

canvasactions/canvasactions.inc, line 74

Code

function canvasactions_imagemask_image(&$image, $action = array()) {

  // Search for full (siteroot) paths, then file dir paths, then relative to the current theme
  $filepath = $action['path'];
  if (!file_exists($filepath)) {
    $filepath = file_create_path($action['path']);
  }
  if (!file_exists($filepath)) {
    trigger_error("Failed to load mask image {$filepath}.", E_USER_ERROR);
    return FALSE;
  }
  $mask = imageapi_image_open($filepath, $image->toolkit);

  // TODO: (sydneyshan) Consider best way to add offset support - I assume we would position the mask somewhere (top/left/offset px etc) and choose if the surrounding area is white or black (opaque or transparent) using an extra form element (radio). Assess exsiting positioning code first to reduce duplication of code. Pass the results to the following function as array($mask, $actions). Perhaps add a 'scale mask to fit image'/'scale image to fit mask'/'no scale' radio group?
  return imageapi_toolkit_invoke('imagemask', $image, array(
    $mask,
  ));
}