You are here

function image_gd_definecanvas in ImageCache Actions 7

Same name and namespace in other branches
  1. 8 canvasactions/canvasactions.inc \image_gd_definecanvas()

GD toolkit specific implementation of the define canvas effect.

Parameters

stdClass $image:

array $data: The parameters for this effect. $data['targetsize'] is an array expected to contain a width, height and a left, top.

Return value

bool true on success, false otherwise.

File

canvasactions/canvasactions.inc, line 367

Code

function image_gd_definecanvas(stdClass $image, array $data) {
  $target_size = $data['targetsize'];
  $RGB = $data['RGB'];
  $newcanvas = imagecreatetruecolor($target_size['width'], $target_size['height']);
  imagesavealpha($newcanvas, TRUE);
  imagealphablending($newcanvas, FALSE);
  imagesavealpha($image->resource, TRUE);
  if ($RGB['HEX']) {

    // Set color, allow it to define transparency, or assume opaque.
    $background = imagecolorallocatealpha($newcanvas, $RGB['red'], $RGB['green'], $RGB['blue'], $RGB['alpha']);
  }
  else {

    // No color, attempt transparency, assume white.
    $background = imagecolorallocatealpha($newcanvas, 255, 255, 255, 127);
  }
  imagefilledrectangle($newcanvas, 0, 0, $target_size['width'], $target_size['height'], $background);
  if ($data['under']) {
    $canvas_object = new stdClass();
    $canvas_object->resource = $newcanvas;
    $canvas_object->info = array(
      'width' => $target_size['width'],
      'height' => $target_size['height'],
      'mime_type' => $image->info['mime_type'],
      'extension' => $image->info['extension'],
    );
    $canvas_object->toolkit = $image->toolkit;
    image_overlay($image, $canvas_object, $target_size['left'], $target_size['top'], 100, TRUE);
  }
  else {
    $image->resource = $newcanvas;
  }
  return TRUE;
}