You are here

function image_gd_definecanvas in ImageCache Actions 8

Same name and namespace in other branches
  1. 7 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 365

Code

function image_gd_definecanvas(stdClass $image, array $data) {
  $targetsize = $data['targetsize'];
  $RGB = $data['RGB'];
  $newcanvas = imagecreatetruecolor($targetsize['width'], $targetsize['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, $targetsize['width'], $targetsize['height'], $background);
  if ($data['under']) {
    $canvas_object = new stdClass();
    $canvas_object->resource = $newcanvas;
    $canvas_object->info = array(
      'width' => $targetsize['width'],
      'height' => $targetsize['height'],
      'mime_type' => $image->info['mime_type'],
      'extension' => $image->info['extension'],
    );
    $canvas_object->toolkit = $image->toolkit;
    image_overlay($image, $canvas_object, $targetsize['left'], $targetsize['top'], 100, TRUE);
  }
  else {
    $image->resource = $newcanvas;
  }
  return TRUE;
}