1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * Image_Canvas 7 * 8 * Canvas based creation of images to facilitate different output formats 9 * 10 * PHP versions 4 and 5 11 * 12 * LICENSE: This library is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU Lesser General Public License as published by 14 * the Free Software Foundation; either version 2.1 of the License, or (at your 15 * option) any later version. This library is distributed in the hope that it 16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 17 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 18 * General Public License for more details. You should have received a copy of 19 * the GNU Lesser General Public License along with this library; if not, write 20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 21 * 02111-1307 USA 22 * 23 * @category Images 24 * @package Image_Canvas 25 * @author Jesper Veggerby <pear.nosey@veggerby.dk> 26 * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen 27 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 28 * @version CVS: $Id: WithMap.php 287471 2009-08-18 23:12:01Z clockwerx $ 29 * @link http://pear.php.net/package/Image_Canvas 30 */ 31 32/** 33 * Class for handling different output formats including a HTML image map 34 * 35 * @category Images 36 * @package Image_Canvas 37 * @author Jesper Veggerby <pear.nosey@veggerby.dk> 38 * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen 39 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 40 * @version Release: @package_version@ 41 * @link http://pear.php.net/package/Image_Canvas 42 * @since version 0.2.0 43 * @abstract 44 */ 45class Image_Canvas_WithMap extends Image_Canvas 46{ 47 48 /** 49 * The image map 50 * @var Image_Canvas_ImageMap 51 * @access private 52 */ 53 var $_imageMap = null; 54 55 /** 56 * Create the canvas. 57 * 58 * Parameters available: 59 * 60 * 'width' The width of the graph on the canvas 61 * 62 * 'height' The height of the graph on the canvas 63 * 64 * 'left' The left offset of the graph on the canvas 65 * 66 * 'top' The top offset of the graph on the canvas 67 * 68 * 'usemap' Initialize an image map 69 * 70 * @param array $params Parameter array 71 * @abstract 72 */ 73 function Image_Canvas_WithMap($params) 74 { 75 parent::Image_Canvas($params); 76 77 if ((isset($params['usemap'])) && ($params['usemap'] === true)) { 78 $this->_imageMap =& Image_Canvas::factory( 79 'ImageMap', 80 array( 81 'left' => $this->_left, 82 'top' => $this->_top, 83 'width' => $this->_width, 84 'height' => $this->_height 85 ) 86 ); 87 } 88 } 89 /** 90 * Draw a line 91 * 92 * Parameter array: 93 * 'x0': int X start point 94 * 'y0': int Y start point 95 * 'x1': int X end point 96 * 'y1': int Y end point 97 * 'color': mixed [optional] The line color 98 * @param array $params Parameter array 99 */ 100 function line($params) 101 { 102 if (isset($this->_imageMap)) { 103 $this->_imageMap->line($params); 104 } 105 parent::line($params); 106 } 107 108 /** 109 * Adds vertex to a polygon 110 * 111 * Parameter array: 112 * 'x': int X point 113 * 'y': int Y point 114 * @param array $params Parameter array 115 */ 116 function addVertex($params) 117 { 118 if (isset($this->_imageMap)) { 119 $this->_imageMap->addVertex($params); 120 } 121 parent::addVertex($params); 122 } 123 124 /** 125 * Adds "splined" vertex to a polygon 126 * 127 * Parameter array: 128 * 'x': int X point 129 * 'y': int Y point 130 * 'p1x': X Control point 1 131 * 'p1y': Y Control point 1 132 * 'p2x': X Control point 2 133 * 'p2y': Y Control point 2 134 * @param array $params Parameter array 135 */ 136 function addSpline($params) 137 { 138 if (isset($this->_imageMap)) { 139 $this->_imageMap->addSpline($params); 140 } 141 parent::addSpline($params); 142 } 143 144 /** 145 * Draws a polygon 146 * 147 * Parameter array: 148 * 'connect': bool [optional] Specifies whether the start point should be 149 * connected to the endpoint (closed polygon) or not (connected line) 150 * 'fill': mixed [optional] The fill color 151 * 'line': mixed [optional] The line color 152 * @param array $params Parameter array 153 */ 154 function polygon($params) 155 { 156 if (isset($this->_imageMap)) { 157 $this->_imageMap->polygon($params); 158 } 159 parent::polygon($params); 160 } 161 162 /** 163 * Draw a rectangle 164 * 165 * Parameter array: 166 * 'x0': int X start point 167 * 'y0': int Y start point 168 * 'x1': int X end point 169 * 'y1': int Y end point 170 * 'fill': mixed [optional] The fill color 171 * 'line': mixed [optional] The line color 172 * @param array $params Parameter array 173 */ 174 function rectangle($params) 175 { 176 if (isset($this->_imageMap)) { 177 $this->_imageMap->rectangle($params); 178 } 179 parent::rectangle($params); 180 } 181 182 /** 183 * Draw an ellipse 184 * 185 * Parameter array: 186 * 'x': int X center point 187 * 'y': int Y center point 188 * 'rx': int X radius 189 * 'ry': int Y radius 190 * 'fill': mixed [optional] The fill color 191 * 'line': mixed [optional] The line color 192 * @param array $params Parameter array 193 */ 194 function ellipse($params) 195 { 196 if (isset($this->_imageMap)) { 197 $this->_imageMap->ellipse($params); 198 } 199 parent::ellipse($params); 200 } 201 202 /** 203 * Draw a pie slice 204 * 205 * Parameter array: 206 * 'x': int X center point 207 * 'y': int Y center point 208 * 'rx': int X radius 209 * 'ry': int Y radius 210 * 'v1': int The starting angle (in degrees) 211 * 'v2': int The end angle (in degrees) 212 * 'srx': int [optional] Starting X-radius of the pie slice (i.e. for a doughnut) 213 * 'sry': int [optional] Starting Y-radius of the pie slice (i.e. for a doughnut) 214 * 'fill': mixed [optional] The fill color 215 * 'line': mixed [optional] The line color 216 * @param array $params Parameter array 217 */ 218 function pieslice($params) 219 { 220 if (isset($this->_imageMap)) { 221 $this->_imageMap->pieslice($params); 222 } 223 parent::pieslice($params); 224 } 225 226 /** 227 * Writes text 228 * 229 * Parameter array: 230 * 'x': int X-point of text 231 * 'y': int Y-point of text 232 * 'text': string The text to add 233 * 'alignment': array [optional] Alignment 234 * 'color': mixed [optional] The color of the text 235 */ 236 function addText($params) 237 { 238 if (isset($this->_imageMap)) { 239 $this->_imageMap->addText($params); 240 } 241 parent::addText($params); 242 } 243 244 /** 245 * Overlay image 246 * 247 * Parameter array: 248 * 'x': int X-point of overlayed image 249 * 'y': int Y-point of overlayed image 250 * 'filename': string The filename of the image to overlay 251 * 'width': int [optional] The width of the overlayed image (resizing if possible) 252 * 'height': int [optional] The height of the overlayed image (resizing if possible) 253 * 'alignment': array [optional] Alignment 254 */ 255 function image($params) 256 { 257 if (isset($this->_imageMap)) { 258 $this->_imageMap->image($params); 259 } 260 parent::image($params); 261 } 262 263 /** 264 * Get the imagemap 265 * @return Image_Graph_ImageMap The image map (or false if none) 266 */ 267 function &getImageMap() 268 { 269 $result = null; 270 if (isset($this->_imageMap)) { 271 $result =& $this->_imageMap; 272 } 273 return $result; 274 } 275 276} 277 278?> 279