Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezimageobject.php
Go to the documentation of this file.
1 <?php
18 class eZImageObject extends eZImageInterface
19 {
20 public $ImageLayerCounter;
22 const ALIGN_AXIS_NONE = 0x00;
23 const ALIGN_AXIS_START = 0x01;
24 const ALIGN_AXIS_STOP = 0x02;
25 const ALIGN_AXIS_CENTER = 0x03; // ALIGN_AXIS_START | ALIGN_AXIS_STOP
26 const ALIGN_AXIS_MASK = 0x03; // ALIGN_AXIS_START | ALIGN_AXIS_STOP
28
31 const PLACE_CONSTANT = 1;
33 const PLACE_RELATIVE = 2;
35
36 public function __construct( $imageObjectRef = null, $imageObject = null, $width = false, $height = false )
37 {
38 parent::__construct( $imageObjectRef, $imageObject, $width, $height );
39 $this->TemplateURI = 'design:image/imageobject.tpl';
40 $this->ImageLayers = array();
41 $this->ImageLayerCounter = 0;
42 }
43
48 function templateData()
49 {
50 return array( 'type' => 'template',
51 'template_variable_name' => 'image',
52 'uri' => $this->TemplateURI );
53 }
54
58 function setTemplateURI( $uri )
59 {
60 $this->TemplateURI = $uri;
61 }
62
74 function calculateAxisPlacement( $value, $type, $alignment, $axisStart, $axisStop, $currentLength )
75 {
76 $pos = 0;
77 if ( $type == self::PLACE_CONSTANT )
78 $pos = $value;
79 else if ( $type == self::PLACE_RELATIVE )
80 {
81 $length = $axisStop - $axisStart;
82 $pos = $value * $length;
83 }
84 $alignment = $alignment & self::ALIGN_AXIS_MASK;
85 if ( $alignment == self::ALIGN_AXIS_NONE or
86 $alignment == self::ALIGN_AXIS_START )
87 return $axisStart + $pos;
88 if ( $alignment == self::ALIGN_AXIS_CENTER )
89 {
90 $length = $axisStop - $axisStart;
91 $halfLength = (int)(($length - $currentLength) / 2);
92 return $axisStart + $halfLength + $value;
93 }
94 else // Align to stop
95 {
96 $pos = $axisStop - $pos - $currentLength;
97 return $pos;
98 }
99 }
100
105 function initializeAxis( $parameters, $name )
106 {
107 $axis = array();
108 if ( isset( $parameters[$name] ) )
109 $axis = $parameters[$name];
110 if ( !isset( $axis['alignment'] ) )
111 $axis['alignment'] = self::ALIGN_AXIS_NONE;
112 if ( !isset( $axis['placement'] ) )
113 $axis['placement'] = self::PLACE_CONSTANT;
114 if ( !isset( $axis['value'] ) )
115 $axis['value'] = 0;
116 return $axis;
117 }
118
124 function calculatePosition( $parameters, $width, $height )
125 {
126 $xAxis = eZImageObject::initializeAxis( $parameters, 'x' );
127 $yAxis = eZImageObject::initializeAxis( $parameters, 'y' );
128 $x = eZImageObject::calculateAxisPlacement( $xAxis['value'], $xAxis['placement'], $xAxis['alignment'],
129 0, $this->width(), $width );
130 $y = eZImageObject::calculateAxisPlacement( $yAxis['value'], $yAxis['placement'], $yAxis['alignment'],
131 0, $this->height(), $height );
132 return array( 'x' => $x,
133 'y' => $y );
134 }
135
139 function getTransparency( $parameters )
140 {
141 if ( !isset( $parameters['transparency'] ) )
142 {
143 return 0.0;
144 }
145 $transparency = max( 0.0, min( 1.0, $parameters['transparency'] ) );
146 return $transparency;
147 }
148
152 function getTransparencyPercent( $parameters )
153 {
154 $transparency = eZImageObject::getTransparency( $parameters );
155 return (int)($transparency * 100.0);
156 }
157
163 function appendLayer( &$imageLayer, $parameters = array() )
164 {
165 if ( !$imageLayer instanceof eZImageLayer )
166 {
167 eZDebug::writeWarning( 'Only eZImageLayer objects may be added as layer items', __METHOD__ );
168 return false;
169 }
170 ++$this->ImageLayerCounter;
171 $layerID = $this->ImageLayerCounter;
172 $this->ImageLayers[] = $layerID;
173 $this->ImageLayerIndex[$layerID] = array( 'image' => &$imageLayer,
174 'parameters' => $parameters );
175 return $layerID;
176 }
177
183 function prependLayer( &$imageLayer, $parameters = array() )
184 {
185 if ( !$imageLayer instanceof eZImageLayer )
186 {
187 eZDebug::writeWarning( 'Only eZImageLayer objects may be added as layer items', __METHOD__ );
188 return false;
189 }
190 ++$this->ImageLayerCounter;
191 $layerID = $this->ImageLayerCounter;
192 $this->ImageLayers = array_merge( array( $layerID ),
193 $this->ImageLayers );
194 $this->ImageLayerIndex[$layerID] = array( 'image' => &$imageLayer,
195 'parameters' => $parameters );
196 return $layerID;
197 }
198
202 function hasLayer( $layerID )
203 {
204 return ( in_array( $layerID, $this->ImageLayers ) and
205 array_key_exists( $layerID, $this->ImageLayerIndex ) );
206 }
207
211 function destroy()
212 {
213 if ( is_array( $this->ImageLayers ) )
214 {
215 foreach( $this->ImageLayers as $item )
216 {
217 if ( $this->ImageLayerIndex[$item]['image'] instanceof eZImageLayer )
218 {
219 $this->ImageLayerIndex[$item]['image']->destroy();
220 }
221 }
222 }
223 parent::destroy();
224 }
225
231 function removeLayer( $layerID )
232 {
233 if ( !in_array( $layerID, $this->ImageLayers ) or
234 !array_key_exists( $layerID, $this->ImageLayerIndex ) )
235 return false;
236 $layerData = $this->ImageLayerIndex[$layerID];
237 unset( $this->ImageLayerIndex[$layerID] );
238 $imageLayers = array();
239 foreach ( $this->ImageLayers as $imageLayerID )
240 {
241 if ( $imageLayerID != $layerID )
242 $imageLayers[] = $imageLayerID;
243 }
244 $this->ImageLayers = $imageLayers;
245 return true;
246 }
247
251 function processImage()
252 {
253 $this->flatten();
254 return true;
255 }
256
261 function flatten()
262 {
263 $i = 0;
264 $hasFirst = false;
265 $firstImageLayer = null;
266 $firstImageLayerData = null;
267 while ( $i < count( $this->ImageLayers ) and
268 !$hasFirst )
269 {
270 $layerID = $this->ImageLayers[$i];
271 $layerData =& $this->ImageLayerIndex[$layerID];
272 $layer = $layerData['image'];
273 if ( $layer instanceof eZImageLayer )
274 {
275 $firstImageLayerData = $layerData;
276 $firstImageLayer = $layer;
277 $hasFirst = true;
278 }
279 else
280 eZDebug::writeWarning( 'Wrong image type ' . gettype( $layer ), __METHOD__ );
281 ++$i;
282 }
283 if ( $hasFirst )
284 {
285 $lastImageLayerData = null;
286 $firstImageLayer->imageObject();
287 if ( !$this->width() )
288 {
289 $this->setWidth( $firstImageLayer->width() );
290 }
291 if ( !$this->height() )
292 {
293 $this->setHeight( $firstImageLayer->height() );
294 }
295 $firstImageLayer->mergeLayer( $this,
296 $firstImageLayerData,
297 $lastImageLayerData );
298 $lastImageLayerData = null;
299 while ( $i < count( $this->ImageLayers ) )
300 {
301 $layerID = $this->ImageLayers[$i];
302 $layerData =& $this->ImageLayerIndex[$layerID];
303 $layer = $layerData['image'];
304 unset( $imageObject );
305 if ( $layer instanceof eZImageLayer )
306 {
307 $layer->mergeLayer( $this,
308 $layerData,
309 $lastImageLayerData );
310 $lastImageLayerData = $layerData;
311 }
312 else
313 {
314 eZDebug::writeWarning( 'Wrong image type ' . gettype( $layer ), __METHOD__ );
315 }
316 ++$i;
317 }
318 return true;
319 }
320 return false;
321 }
322
324 public $ImageLayers;
325 public $TemplateURI;
326 public $ImageLayerIndex;
327 }
328
329 ?>
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZImageInterface
Base interface for all image object and layer classes.
Definition: ezimageinterface.php:20
eZImageInterface\width
width()
Definition: ezimageinterface.php:555
eZImageInterface\setWidth
setWidth( $w)
Definition: ezimageinterface.php:571
eZImageInterface\height
height()
Definition: ezimageinterface.php:563
eZImageInterface\setHeight
setHeight( $h)
Definition: ezimageinterface.php:579
eZImageLayer
Defines a layer in a image object.
Definition: ezimagelayer.php:19
eZImageObject
Image object which handles image layers.
Definition: ezimageobject.php:19
eZImageObject\processImage
processImage()
Definition: ezimageobject.php:251
eZImageObject\prependLayer
prependLayer(&$imageLayer, $parameters=array())
Definition: ezimageobject.php:183
eZImageObject\setTemplateURI
setTemplateURI( $uri)
Definition: ezimageobject.php:58
eZImageObject\ALIGN_AXIS_STOP
const ALIGN_AXIS_STOP
Definition: ezimageobject.php:24
eZImageObject\getTransparencyPercent
getTransparencyPercent( $parameters)
Definition: ezimageobject.php:152
eZImageObject\__construct
__construct( $imageObjectRef=null, $imageObject=null, $width=false, $height=false)
Definition: ezimageobject.php:36
eZImageObject\ALIGN_AXIS_MASK
const ALIGN_AXIS_MASK
Definition: ezimageobject.php:26
eZImageObject\initializeAxis
initializeAxis( $parameters, $name)
Definition: ezimageobject.php:105
eZImageObject\calculatePosition
calculatePosition( $parameters, $width, $height)
Definition: ezimageobject.php:124
eZImageObject\getTransparency
getTransparency( $parameters)
Definition: ezimageobject.php:139
eZImageObject\PLACE_CONSTANT
const PLACE_CONSTANT
Definition: ezimageobject.php:31
eZImageObject\destroy
destroy()
Definition: ezimageobject.php:211
eZImageObject\flatten
flatten()
Definition: ezimageobject.php:261
eZImageObject\templateData
templateData()
Definition: ezimageobject.php:48
eZImageObject\removeLayer
removeLayer( $layerID)
Definition: ezimageobject.php:231
eZImageObject\$ImageLayers
$ImageLayers
Definition: ezimageobject.php:324
eZImageObject\PLACE_RELATIVE
const PLACE_RELATIVE
Places the layer relative to the axis size.
Definition: ezimageobject.php:33
eZImageObject\ALIGN_AXIS_START
const ALIGN_AXIS_START
Definition: ezimageobject.php:23
eZImageObject\appendLayer
appendLayer(&$imageLayer, $parameters=array())
Definition: ezimageobject.php:163
eZImageObject\ALIGN_AXIS_NONE
const ALIGN_AXIS_NONE
Alignment values.
Definition: ezimageobject.php:22
eZImageObject\$TemplateURI
$TemplateURI
Definition: ezimageobject.php:325
eZImageObject\$ImageLayerCounter
$ImageLayerCounter
Definition: ezimageobject.php:20
eZImageObject\calculateAxisPlacement
calculateAxisPlacement( $value, $type, $alignment, $axisStart, $axisStop, $currentLength)
Definition: ezimageobject.php:74
eZImageObject\ALIGN_AXIS_CENTER
const ALIGN_AXIS_CENTER
Definition: ezimageobject.php:25
eZImageObject\hasLayer
hasLayer( $layerID)
Definition: ezimageobject.php:202
eZImageObject\$ImageLayerIndex
$ImageLayerIndex
Definition: ezimageobject.php:326
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.