imagecache_canvasactions.module in ImageCache Actions 5.2
Same filename and directory in other branches
A collection of canvas (layer) type manipulations for imagecache - including "Watermark"
Based on first draft of the code by Dimm (imagecache.module 5--1) http://drupal.org/node/184816
Rewritten and ported to Imagecache actions API (imagecache.module 5--2) by dman http://coders.co.nz/
Notes about imagecache action extensions. For each action:
1: Impliment imagecache_HOOK_form($formdata) to define the config form.
1a: Impliment theme_imagecache_HOOK_form if needed - optional
2: Impliment imagecache_HOOK_image(&$image, $data) to DO the process
3: Impliment theme_imagecache_HOOK($element) to return a text description of the setting
4: Declare the action in HOOK_imagecache_actions()
API ref for hook_image()
File
imagecache_canvasactions.moduleView source
<?php
/**
* @file A collection of canvas (layer) type manipulations for imagecache -
* including "Watermark"
*
* Based on first draft of the code by Dimm (imagecache.module 5--1)
* http://drupal.org/node/184816
*
* Rewritten and ported to Imagecache actions API (imagecache.module 5--2) by
* dman http://coders.co.nz/
*
*
* Notes about imagecache action extensions. For each action:
*
* 1: Impliment imagecache_HOOK_form($formdata) to define the config form.
*
* 1a: Impliment theme_imagecache_HOOK_form if needed - optional
*
* 2: Impliment imagecache_HOOK_image(&$image, $data) to DO the process
*
* 3: Impliment theme_imagecache_HOOK($element) to return a text description of
* the setting
*
* 4: Declare the action in HOOK_imagecache_actions()
*
*
* API ref for hook_image()
*
* @param $image array defining an image file, including :
*
* $image- >source as the filename,
*
* $image->info array
*
* $image->resource handle on the image object
*
* @param $action array of settings as defined in your form.
*
*/
// During devel, caching is pointless. Flush it
// imagecache_action_definitions(TRUE);
require_once 'utility.inc';
/**
* Implementation of hook_imagecache_actions().
*
* Declare available actions, return help text about this filter.
*
* These funcs are all in their respective include libraries - as configured below
*/
function imagecache_canvasactions_imagecache_actions() {
$actions = array(
'canvasactions_definecanvas' => array(
'name' => t('Define Canvas'),
'description' => t('Define the size of the working canvas and background color, this controls the dimensions of the output image..'),
'file' => 'canvasactions.inc',
),
'canvasactions_source2canvas' => array(
'name' => t('Overlay: source image to canvas'),
'description' => t('Places the source image onto the canvas for compositing.'),
'file' => 'canvasactions.inc',
),
'canvasactions_file2canvas' => array(
'name' => t('Overlay: file image to canvas (watermark)'),
'description' => t(' Choose the file image you wish to use as an overlay, and position it in a layer on top of the canvas.'),
'file' => 'canvasactions.inc',
),
'canvasactions_canvas2file' => array(
'name' => t('Underlay: place a file image under the current image (background)'),
'description' => t(' Choose the file image you wish to use as an background, and position the processed image on it.'),
'file' => 'canvasactions.inc',
),
'canvasactions_roundedcorners' => array(
'name' => t('Rounded Corners (individually configurable)'),
'description' => t(' This is true cropping, not overlays, so the result <em>can</em> be transparent.'),
'file' => 'canvasactions.inc',
),
);
return $actions;
}
//////////////////////
// imageapi extensions
// Maybe shift into there one day
/**
* Place one image over another
*
* @param $overlay may be a filename or an imageAPI object
* @return bool success
* @ingroup imageapi
*/
function imageapi_image_overlay(&$image, $overlay, $x, $y, $alpha) {
return call_user_func_array($image->toolkit . '_image_overlay', array(
&$image,
$overlay,
$x,
$y,
$alpha,
));
}
/**
* Place one image over another
* This modifies the passed image by reference
*
* @ingroup imageapi
* @param $overlay may be a filename or an imageAPI object
* @param alpha from 0-100.
* @return bool success
*/
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;
}
/**
* Place text on an image.
*
* @ingroup imageapi
*
*/
function imageapi_image_overlaytext(&$image, $text, $size = 12, $x = 0, $y = 0, $RGB = 0, $fontfile = 'MgOpenModernaBold', $angle = 0) {
return call_user_func($image->toolkit . '_image_overlaytext', $image, $text, $size, $x, $y, $RGB, $fontfile, $angle);
}
/**
* Place text on an image.
*
* @ingroup imageapi
*
*/
function imageapi_gd_image_overlaytext(&$image, $text, $size = 12, $x = 0, $y = 0, $RGB, $fontfile = 'MgOpenModernaBold', $angle = 0) {
$color = imagecolorallocate($image->resource, $RGB['red'], $RGB['green'], $RGB['blue']);
imagettftext($image->resource, $size, $angle, $x, $y, $color, $fontfile, $text);
return TRUE;
}
Functions
Name | Description |
---|---|
imageapi_gd_image_overlay | Place one image over another This modifies the passed image by reference |
imageapi_gd_image_overlaytext | Place text on an image. |
imageapi_image_overlay | Place one image over another |
imageapi_image_overlaytext | Place text on an image. |
imagecache_canvasactions_imagecache_actions | Implementation of hook_imagecache_actions(). |