You are here

function imageapi_gd_image_overlay in ImageCache Actions 5.2

Same name and namespace in other branches
  1. 5.3 imagecache_canvasactions.module \imageapi_gd_image_overlay()
  2. 6 imagecache_canvasactions.module \imageapi_gd_image_overlay()

Place one image over another This modifies the passed image by reference

Parameters

$overlay may be a filename or an imageAPI object:

alpha from 0-100.:

Return value

bool success

File

./imagecache_canvasactions.module, line 116
A collection of canvas (layer) type manipulations for imagecache - including "Watermark"

Code

function imageapi_gd_image_overlay(&$image, $overlay, $x, $y, $alpha) {
  if (is_string($overlay)) {
    if (!file_exists($overlay)) {
      watchdog('imagecache', 'Image file does not exist. Attempted to overlay $overlay');
    }
    $overlay = imageapi_image_open($overlay);
  }
  $x_ins = _imagecache_keyword_filter($x, $image->info['width'], $overlay->info['width']);
  $y_ins = _imagecache_keyword_filter($y, $image->info['height'], $overlay->info['height']);

  // imagecopymerge doesn't do alpha transparancy right?

  //imagealphablending($image->resource, false);

  //imagesavealpha($image->resource, TRUE);

  //imagealphablending($overlay->resource, false);

  //imagesavealpha($overlay->resource, TRUE);

  // imagecopymerge($image->resource, $overlay->resource, $x_ins, $y_ins, 0, 0, $overlay->info['width'], $overlay->info['height'], $alpha);
  // Silly thing, it's easy. Use the attached library below instead
  require_once 'watermark.inc';
  $watermark = new watermark();
  $image->resource = $watermark
    ->create_watermark($image->resource, $overlay->resource, $x_ins, $y_ins, $alpha);
  imagedestroy($overlay->resource);
  return TRUE;
}