/[drupal]/contributions/modules/imagecache_actions/imagecache_canvasactions.module
ViewVC logotype

Contents of /contributions/modules/imagecache_actions/imagecache_canvasactions.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Tue Aug 19 14:26:10 2008 UTC (15 months, 1 week ago) by dman
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +3 -28 lines
File MIME type: text/x-php
Split the text process off into a submodule, removed it from
canvasactions
Merged the 'dynamic' caption function from
http://drupal.org/node/264862
into the text module

Attempted to address the imagecache profile cache problem where new
action modules do not show up on when enabled
1 <?php
2 // $Id: imagecache_canvasactions.module,v 1.2 2008/05/28 13:18:41 dman Exp $
3
4 /**
5 * @file A collection of canvas (layer) type manipulations for imagecache -
6 * including "Watermark"
7 *
8 * Based on first draft of the code by Dimm (imagecache.module 5--1)
9 * http://drupal.org/node/184816
10 *
11 * Rewritten and ported to Imagecache actions API (imagecache.module 5--2) by
12 * dman http://coders.co.nz/
13 *
14 *
15 * Notes about imagecache action extensions. For each action:
16 *
17 * 1: Impliment imagecache_HOOK_form($formdata) to define the config form.
18 *
19 * 1a: Impliment theme_imagecache_HOOK_form if needed - optional
20 *
21 * 2: Impliment imagecache_HOOK_image(&$image, $data) to DO the process
22 *
23 * 3: Impliment theme_imagecache_HOOK($element) to return a text description of
24 * the setting
25 *
26 * 4: Declare the action in HOOK_imagecache_actions()
27 *
28 *
29 * API ref for hook_image()
30 *
31 * @param $image array defining an image file, including :
32 *
33 * $image- >source as the filename,
34 *
35 * $image->info array
36 *
37 * $image->res handle on the image object
38 *
39 * @param $action array of settings as defined in your form.
40 *
41 */
42
43 // During devel, caching is pointless. Flush it
44 // imagecache_action_definitions(TRUE);
45
46 require_once('utility.inc');
47
48 /**
49 * Implementation of hook_imagecache_actions().
50 *
51 * Declare available actions, return help text about this filter.
52 *
53 * These funcs are all in their respective include libraries - as configured below
54 */
55 function imagecache_canvasactions_imagecache_actions() {
56
57 $actions = array(
58 'canvasactions_definecanvas' => array(
59 'name' => t('Define Canvas'),
60 'description' => t('Define the size of the working canvas and background color, this controls the dimensions of the output image..'),
61 'file' => 'canvasactions.inc',
62 ),
63 'canvasactions_source2canvas' => array(
64 'name' => t('Overlay: source image to canvas'),
65 'description' => t('Places the source image onto the canvas for compositing.'),
66 'file' => 'canvasactions.inc',
67 ),
68 'canvasactions_file2canvas' => array(
69 'name' => t('Overlay: file image to canvas (watermark)'),
70 'description' => t(' Choose the file image you wish to use as an overlay, and position it in a layer on top of the canvas.'),
71 'file' => 'canvasactions.inc',
72 ),
73 'canvasactions_canvas2file' => array(
74 'name' => t('Underlay: place a file image under the current image (background)'),
75 'description' => t(' Choose the file image you wish to use as an background, and position the processed image on it.'),
76 'file' => 'canvasactions.inc',
77 ),
78 );
79
80 return $actions;
81 }
82
83
84
85
86
87 /**
88 * Need to flush the cache when this module is enabled
89 */
90 function imagecache_canvasactions_install() {
91 imagecache_action_definitions(TRUE);
92 cache_clear_all('imagecache_actions', 'cache');
93 drupal_set_message(t('Additional imagecache actions should now be available in the presets !settings_link', array('!settings_link' => l(t('settings'), 'admin/build/imagecache'))));
94 }
95
96
97 //////////////////////
98 // imageapi extensions
99 // Maybe shift into there one day
100
101 /**
102 * Place one image over another
103 *
104 * @param $overlay may be a filename or an imageAPI object
105 * @return bool success
106 * @ingroup imageapi
107 */
108 function imageapi_image_overlay(&$image, $overlay, $x, $y, $alpha) {
109 return call_user_func_array($image->toolkit .'_image_overlay', array(&$image, $overlay, $x, $y, $alpha));
110 }
111
112 /**
113 * Place one image over another
114 * This modifies the passed image by reference
115 *
116 * @ingroup imageapi
117 * @param $overlay may be a filename or an imageAPI object
118 * @param alpha from 0-100.
119 * @return bool success
120 */
121 function imageapi_gd_image_overlay(&$image, $overlay, $x, $y, $alpha) {
122 if (is_string($overlay) ) {
123 if (! file_exists($overlay)) {
124 watchdog('imagecache', 'Image file does not exist. Attempted to overlay $overlay');
125 }
126 $overlay = imageapi_image_open($overlay);
127 }
128
129 $x_ins = _imagecache_keyword_filter($x, $image->info['width'], $overlay->info['width']);
130 $y_ins = _imagecache_keyword_filter($y, $image->info['height'], $overlay->info['height']);
131
132 // imagecopymerge doesn't do alpha transparency right?
133 //imagealphablending($image->res, false);
134 //imagesavealpha($image->res, TRUE);
135 //imagealphablending($overlay->res, false);
136 //imagesavealpha($overlay->res, TRUE);
137 // imagecopymerge($image->res, $overlay->res, $x_ins, $y_ins, 0, 0, $overlay->info['width'], $overlay->info['height'], $alpha);
138 // Silly thing, it's easy. Use the attached library below instead
139
140 require_once('watermark.inc');
141 $watermark = new watermark();
142 $image->res = $watermark->create_watermark($image->res, $overlay->res, $x_ins, $y_ins, $alpha);
143
144 imagedestroy($overlay->res);
145 return TRUE;
146 }
147
148

  ViewVC Help
Powered by ViewVC 1.1.2