|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZTemplateImageOperator class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package lib 00009 */ 00010 00011 /*! 00012 \class eZTemplateImageOperator eztemplateimageoperator.php 00013 \ingroup eZTemplateOperators 00014 \brief Text to image conversion using operator "texttoimage" 00015 00016 This operator allows a piece of text be converted to an image file representing 00017 the text. The output image is written in PNG format. 00018 Use setFontDir() and setCacheDir() to change where the font is located and where 00019 the cache file should be put. 00020 If fontDir() is an empty string the font will be looked for in the system. 00021 */ 00022 00023 class eZTemplateImageOperator 00024 { 00025 /*! 00026 Initializes the image operator with the operator name $name. 00027 */ 00028 function eZTemplateImageOperator( $texttoimageName = "texttoimage", 00029 $imageName = "image", 00030 $imagefileName = "imagefile" ) 00031 { 00032 $this->Operators = array( $texttoimageName, 00033 $imageName, 00034 $imagefileName ); 00035 00036 $ini = eZINI::instance( 'texttoimage.ini' ); 00037 $fontDirs = $ini->variable( "PathSettings", "FontDir" ); 00038 $this->FontDir = array(); 00039 foreach ( $fontDirs as $fontDir ) 00040 { 00041 $this->FontDir[] = $fontDir; 00042 } 00043 $this->CacheDir = $ini->variable( "PathSettings", "CacheDir" ); 00044 $this->HTMLDir = eZSys::wwwDir() . $ini->variable( "PathSettings", "HtmlDir" ); 00045 00046 $this->DefaultClass = 'default'; 00047 $this->Family = "arial"; 00048 $this->Colors = array( "bgcolor" => array( 255, 255, 255 ), 00049 "textcolor" => array( 0, 0, 0 ) ); 00050 $this->PointSize = 12; 00051 $this->Angle = 0; 00052 $this->XAdjust = 0; 00053 $this->YAdjust = 0; 00054 $this->WAdjust = 0; 00055 $this->HAdjust = 0; 00056 $this->UseCache = true; 00057 if ( $ini->variable( "ImageSettings", "UseCache" ) == "disabled" ) 00058 $this->UseCache = false; 00059 00060 $functions = array( "ImageTTFBBox", 00061 "ImageCreate", 00062 "ImageColorAllocate", 00063 "ImageColorAllocate", 00064 "ImageTTFText", 00065 "ImagePNG", 00066 "ImageJPEG", 00067 "ImageDestroy" ); 00068 $this->MissingGDFunctions = array(); 00069 foreach ( $functions as $function ) 00070 { 00071 if ( !function_exists( $function ) ) 00072 $this->MissingGDFunctions[] = $function; 00073 } 00074 $this->ImageGDSupported = count( $this->MissingGDFunctions ) == 0; 00075 } 00076 00077 function operatorTemplateHints() 00078 { 00079 return array( 'texttoimage' => array( 'input' => true, 00080 'output' => true, 00081 'output-type' => array( 'objectproxy', 'keep' ), 00082 'parameters' => true ), 00083 'image' => array( 'input' => false, 00084 'output' => true, 00085 'output-type' => array( 'objectproxy', 'keep' ), 00086 'parameters' => true ), 00087 'imagefile' => array( 'input' => false, 00088 'output' => true, 00089 'output-type' => 'objectproxy', 00090 'parameters' => true ) ); 00091 } 00092 00093 /*! 00094 Performs image conversion using Image GD and returns the html 00095 text for the image. 00096 */ 00097 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$inputValue, $namedParameters, 00098 $placement ) 00099 { 00100 if ( !$this->ImageGDSupported ) 00101 { 00102 eZDebug::writeError( "$operatorName cannot be used since the following ImageGD functions are missing: " . implode( ', ', $this->MissingGDFunctions ) ); 00103 return; 00104 } 00105 00106 if ( $operatorName == 'texttoimage' ) 00107 { 00108 $class = $namedParameters['class']; 00109 00110 $family = $this->Family; 00111 $size = $this->PointSize; 00112 $angle = $this->Angle; 00113 $xadj = $this->XAdjust; 00114 $yadj = $this->YAdjust; 00115 $wadj = $this->WAdjust; 00116 $hadj = $this->HAdjust; 00117 $usecache = $this->UseCache; 00118 $bgcol = $this->color( "bgcolor" ); 00119 $textcol = $this->color( "textcolor" ); 00120 00121 $ini = eZINI::instance( 'texttoimage.ini' ); 00122 $family = $ini->variable( 'DefaultSettings', 'Family' ); 00123 $size = $ini->variable( 'DefaultSettings', 'PointSize' ); 00124 $angle = $ini->variable( 'DefaultSettings', 'Angle' ); 00125 $xadj = $ini->variable( 'DefaultSettings', 'XAdjustment' ); 00126 $yadj = $ini->variable( 'DefaultSettings', 'YAdjustment' ); 00127 $wadj = $ini->variable( 'DefaultSettings', 'WidthAdjustment' ); 00128 $hadj = $ini->variable( 'DefaultSettings', 'HeightAdjustment' ); 00129 $bgcol = $this->decodeColor( $ini->variable( 'DefaultSettings', 'BackgroundColor' ) ); 00130 $textcol = $this->decodeColor( $ini->variable( 'DefaultSettings', 'TextColor' ) ); 00131 00132 $absoluteWidth = false; 00133 $absoluteHeight = false; 00134 00135 if ( $ini->hasVariable( $class, 'Family' ) ) 00136 $family = $ini->variable( $class, 'Family' ); 00137 if ( $ini->hasVariable( $class, 'PointSize' ) ) 00138 $size = $ini->variable( $class, 'PointSize' ); 00139 if ( $ini->hasVariable( $class, 'Angle' ) ) 00140 $angle = $ini->variable( $class, 'Angle' ); 00141 if ( $ini->hasVariable( $class, 'XAdjustment' ) ) 00142 $xadj = $ini->variable( $class, 'XAdjustment' ); 00143 if ( $ini->hasVariable( $class, 'YAdjustment' ) ) 00144 $yadj = $ini->variable( $class, 'YAdjustment' ); 00145 if ( $ini->hasVariable( $class, 'WidthAdjustment' ) ) 00146 $wadj = $ini->variable( $class, 'WidthAdjustment' ); 00147 if ( $ini->hasVariable( $class, 'HeightAdjustment' ) ) 00148 $hadj = $ini->variable( $class, 'HeightAdjustment' ); 00149 if ( $ini->hasVariable( $class, 'BackgroundColor' ) ) 00150 $bgcol = $this->decodeColor( $ini->variable( $class, 'BackgroundColor' ) ); 00151 if ( $ini->hasVariable( $class, 'TextColor' ) ) 00152 $textcol = $this->decodeColor( $ini->variable( $class, 'TextColor' ) ); 00153 if ( $ini->hasVariable( $class, 'AbsoluteWidth' ) ) 00154 $absoluteWidth = $ini->variable( $class, 'AbsoluteWidth' ); 00155 if ( $ini->hasVariable( $class, 'AbsoluteHeight' ) ) 00156 $absoluteHeight = $ini->variable( $class, 'AbsoluteHeight' ); 00157 00158 if ( $namedParameters['family'] !== null ) 00159 $family = $namedParameters["family"]; 00160 if ( $namedParameters["pointsize"] !== null ) 00161 $size = $namedParameters["pointsize"]; 00162 if ( $namedParameters["angle"] !== null ) 00163 $angle = $namedParameters["angle"]; 00164 if ( $namedParameters["x"] !== null ) 00165 $xadj = $namedParameters["x"]; 00166 if ( $namedParameters["y"] !== null ) 00167 $yadj = $namedParameters["y"]; 00168 if ( $namedParameters["w"] !== null ) 00169 $wadj = $namedParameters["w"]; 00170 if ( $namedParameters["h"] !== null ) 00171 $hadj = $namedParameters["h"]; 00172 if ( $namedParameters["usecache"] !== null ) 00173 $usecache = $namedParameters["usecache"]; 00174 if ( $namedParameters["bgcolor"] !== null ) 00175 $bgcol = $this->decodeColor( $namedParameters["bgcolor"] ); 00176 if ( $namedParameters["textcolor"] !== null ) 00177 $textcol = $this->decodeColor( $namedParameters["textcolor"] ); 00178 $storeImage = $namedParameters["storeimage"]; 00179 00180 $fontDir = false; 00181 foreach ( $this->FontDir as $fontPath ) 00182 { 00183 if ( eZImageFont::exists( $family, $fontPath ) ) 00184 { 00185 $fontDir = $fontPath; 00186 break; 00187 } 00188 } 00189 if ( !$fontDir ) 00190 return; 00191 $font = new eZImageFont( $family, $size, $fontDir, $xadj, $yadj ); 00192 00193 if ( $bgcol === null ) 00194 $bgcol = $this->color( "bgcolor" ); 00195 if ( !is_array( $bgcol ) or 00196 count( $bgcol ) < 3 ) 00197 $bgcol = array( 255, 255, 255 ); 00198 if ( $textcol === null ) 00199 $textcol = $this->color( "textcolor" ); 00200 if ( !is_array( $textcol ) or 00201 count( $textcol ) < 3 ) 00202 $textcol = array( 0, 0, 0 ); 00203 00204 $alternativeText = htmlspecialchars( $inputValue ); 00205 if ( is_string( $usecache ) ) 00206 $md5Text = $usecache; 00207 else 00208 $md5Text = md5( $inputValue . $family . $size . $angle . $xadj . $yadj . $wadj . $hadj . $absoluteWidth . $absoluteHeight . implode( ",", $bgcol ) . implode( ",", $textcol ) ); 00209 if ( is_string( $usecache ) or !$usecache or 00210 !$this->hasImage( $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs ) ) 00211 { 00212 $layer = eZImageTextLayer::createForText( $inputValue, $font, 00213 $wadj, $hadj, $angle, 00214 $absoluteWidth, $absoluteHeight ); 00215 if ( !$layer ) 00216 { 00217 $tpl->error( $operatorName, "Could not open font \"$family\", no image created", $placement ); 00218 return; 00219 } 00220 $layer->allocateColor( 'bgcol', $bgcol[0], $bgcol[1], $bgcol[2] ); 00221 $layer->allocateColor( 'textcol', $textcol[0], $textcol[1], $textcol[2] ); 00222 $layer->setTextColor( 'textcol' ); 00223 00224 if ( $storeImage ) 00225 $this->storeImage( $layer, $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs ); 00226 $layer->destroy(); 00227 } 00228 else 00229 { 00230 $layer = $this->loadImage( $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs ); 00231 } 00232 $layer->setAlternativeText( $alternativeText ); 00233 $inputValue = $layer; 00234 } 00235 00236 else if ( $operatorName == 'image' ) 00237 { 00238 $useCache = $this->UseCache; 00239 $image = new eZImageObject(); 00240 $md5Input = "image\n"; 00241 $alternativeText = ''; 00242 $this->readImageParameters( $tpl, $image, $operatorParameters, $rootNamespace, $currentNamespace, $md5Input, $alternativeText, 00243 $placement ); 00244 $image->setAlternativeText( $alternativeText ); 00245 $md5Text = md5( $md5Input ); 00246 if ( !$useCache or 00247 !$this->hasImage( $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs ) ) 00248 { 00249 $this->storeImage( $image, $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs ); 00250 $image->destroy(); 00251 $inputValue = $image; 00252 } 00253 else 00254 { 00255 $this->setLoadImage( $image, $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs ); 00256 $image->load(); 00257 $inputValue = $image; 00258 } 00259 } 00260 else if ( $operatorName == 'imagefile' ) 00261 { 00262 $file =& $namedParameters['filename']; 00263 $options =& $namedParameters['options']; 00264 $dir = ''; 00265 if ( preg_match( "#^(.+)/([^/]+)$#", $file, $matches ) ) 00266 { 00267 $dir = $matches[1]; 00268 $file = $matches[2]; 00269 } 00270 00271 $layer = eZImageLayer::createForFile( $file, $dir ); 00272 $alternativeText = $file; 00273 if ( preg_match( "#(.+)\.([^.]+)$#", $file, $matches ) ) 00274 $alternativeText = $matches[1]; 00275 $layer->setAlternativeText( $alternativeText ); 00276 $inputValue = $layer; 00277 } 00278 } 00279 00280 /*! 00281 Returns the operators in this class. 00282 */ 00283 function operatorList() 00284 { 00285 return $this->Operators; 00286 } 00287 00288 /*! 00289 \return true to tell the template engine that the parameter list exists per operator type. 00290 */ 00291 function namedParameterPerOperator() 00292 { 00293 return true; 00294 } 00295 00296 /*! 00297 See eZTemplateOperator::namedParameterList 00298 */ 00299 function namedParameterList() 00300 { 00301 return array( 'texttoimage' => array( "class" => array( 'type' => 'string', 00302 'required' => false, 00303 'default' => $this->DefaultClass ), 00304 "family" => array( "type" => "string", 00305 "required" => false, 00306 "default" => null ), 00307 "pointsize" => array( "type" => "integer", 00308 "required" => false, 00309 "default" => null ), 00310 "angle" => array( "type" => "integer", 00311 "required" => false, 00312 "default" => null ), 00313 "bgcolor" => array( "type" => "mixed", 00314 "required" => false, 00315 "default" => null ), 00316 "textcolor" => array( "type" => "mixed", 00317 "required" => false, 00318 "default" => null ), 00319 "x" => array( "type" => "integer", 00320 "required" => false, 00321 "default" => null ), 00322 "y" => array( "type" => "integer", 00323 "required" => false, 00324 "default" => null ), 00325 "w" => array( "type" => "integer", 00326 "required" => false, 00327 "default" => null ), 00328 "h" => array( "type" => "integer", 00329 "required" => false, 00330 "default" => null ), 00331 "usecache" => array( "type" => "boolean", 00332 "required" => false, 00333 "default" => null ), 00334 "storeimage" => array( "type" => "boolean", 00335 "required" => false, 00336 "default" => true ) 00337 ), 00338 'imagefile' => array( 'filename' => array( 'type' => 'string', 00339 'required' => true ), 00340 'options' => array( 'type' => 'array', 00341 'default' => array(), 00342 'required' => false ) ) ); 00343 } 00344 00345 /*! 00346 \return the directory where fonts are located. If it is empty 00347 the font is looked for in the system font dirs. 00348 \sa setFontDir 00349 */ 00350 function fontDir() 00351 { 00352 return $this->FontDir; 00353 } 00354 00355 /*! 00356 \return the directory where images are created. 00357 \sa setCacheDir 00358 */ 00359 function cacheDir() 00360 { 00361 return $this->CacheDir; 00362 } 00363 00364 /*! 00365 \return the directory where image is accessible from HTML code. 00366 \sa setHTMLdir 00367 */ 00368 function htmlDir() 00369 { 00370 return $this->HTMLDir; 00371 } 00372 00373 /*! 00374 \return the family name of the default font. 00375 \sa setFamily 00376 */ 00377 function family() 00378 { 00379 return $this->Family; 00380 } 00381 00382 /*! 00383 \return the pointsize of the default font. 00384 \sa setPointsize 00385 */ 00386 function pointSize() 00387 { 00388 return $this->PointSize; 00389 } 00390 00391 /*! 00392 \return the angle at which the font is rendered. 00393 */ 00394 function angle() 00395 { 00396 return $this->Angle; 00397 } 00398 00399 /*! 00400 \return the number of pixels the font is adjusted in the X direction. 00401 \sa setXAdjustment, yAdjustment 00402 */ 00403 function xAdjustment() 00404 { 00405 return $this->XAdjust; 00406 } 00407 00408 /*! 00409 \return the number of pixels the font is adjusted in the Y direction. 00410 \sa setYAdjustment, xAdjustment 00411 */ 00412 function yAdjustment() 00413 { 00414 return $this->YAdjust; 00415 } 00416 00417 /*! 00418 \return the number of pixels the width of the image is adjusted. 00419 \sa setWidthAdjustment, heightAdjustment 00420 */ 00421 function widthAdjustment() 00422 { 00423 return $this->WAdjust; 00424 } 00425 00426 /*! 00427 \return the number of pixels the height of the image is adjusted. 00428 \sa setHeightAdjustment, widthAdjustment 00429 */ 00430 function heightAdjustment() 00431 { 00432 return $this->HAdjust; 00433 } 00434 00435 /*! 00436 \return true if image cache should be reused if the image text etc.. hasn't changed. 00437 */ 00438 function useCache() 00439 { 00440 return $this->UseCache; 00441 } 00442 00443 /*! 00444 \return the array of colors in use 00445 */ 00446 function colors() 00447 { 00448 return $this->Colors; 00449 } 00450 00451 /*! 00452 Takes a mixed mode color representation and decodes it to a an array of three elements 00453 which represents the R, G and B color elements. 00454 */ 00455 function decodeColor( /*! The mixed color mode */ $col ) 00456 { 00457 $decode = null; 00458 if ( is_array( $col ) ) 00459 $decode = $col; 00460 else if ( is_string( $col ) ) 00461 { 00462 if ( preg_match( "/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/", $col, $regs ) ) 00463 $decode = array( hexdec( $regs[1] ), hexdec( $regs[2] ), hexdec( $regs[3] ) ); 00464 } 00465 return $decode; 00466 } 00467 00468 /*! 00469 Returns the decodecd color for colorname $colname 00470 */ 00471 function color( $colname ) 00472 { 00473 if ( isset( $this->Colors[$colname] ) ) 00474 { 00475 $col = $this->Colors[$colname]; 00476 return $this->decodeColor( $col ); 00477 } 00478 return null; 00479 } 00480 00481 /*! 00482 Sets the font directory, see fontDir() for more information. 00483 \sa fontDir 00484 */ 00485 function setFontDir( $dir ) 00486 { 00487 $this->FontDir = $dir; 00488 } 00489 00490 /*! 00491 Sets the directory where images are created. 00492 \sa cacheDir 00493 */ 00494 function setCacheDir( $dir ) 00495 { 00496 $this->CacheDir = $dir; 00497 } 00498 00499 /*! 00500 Sets the directory which the HTML code uses to acces the image. 00501 \sa htmlDir 00502 */ 00503 function setHTMLDir( $dir ) 00504 { 00505 $this->HTMLDir = $dir; 00506 } 00507 00508 /*! 00509 Sets the font family for the default font. 00510 */ 00511 function setFamily( $fam ) 00512 { 00513 $this->Family = $fam; 00514 } 00515 00516 /*! 00517 Sets the pointsize for the default font. 00518 */ 00519 function setPointSize( $size ) 00520 { 00521 $this->PointSize = $size; 00522 } 00523 00524 /*! 00525 Sets the angle for the default font. 00526 */ 00527 function setAngle( $ang ) 00528 { 00529 $this->Angle = $ang; 00530 } 00531 00532 /*! 00533 Adjustment in the x axis. 00534 \sa xAdjustment, yAdjustment, setYAdjustment 00535 */ 00536 function setXAdjustment( $x ) 00537 { 00538 $this->XAdjust = $x; 00539 } 00540 00541 /*! 00542 Adjustment in the y axis. 00543 \sa xAdjustment, yAdjustment, setXAdjustment 00544 */ 00545 function setYAdjustment( $y ) 00546 { 00547 $this->YAdjust = $y; 00548 } 00549 00550 /*! 00551 Adjustment for width. 00552 \sa widthAdjustment, heightAdjustment, setHeightAdjustment 00553 */ 00554 function setWidthAdjustment( $w ) 00555 { 00556 $this->WAdjust = $w; 00557 } 00558 00559 /*! 00560 Adjustment for height. 00561 \sa widthAdjustment, heightAdjustment, setWidthAdjustment 00562 */ 00563 function setHeightAdjustment( $h ) 00564 { 00565 $this->HAdjust = $h; 00566 } 00567 00568 /*! 00569 Sets whether to reuse cache files or not. 00570 \sa useCache 00571 */ 00572 function setUseCache( $use ) 00573 { 00574 $this->UseCache = $use; 00575 } 00576 00577 /*! 00578 Sets all the colors. 00579 \sa setColor, color 00580 */ 00581 function setColors( $cols ) 00582 { 00583 $this->Colors = $cols; 00584 } 00585 00586 /*! 00587 Sets the colorname $colname to color value $colval. 00588 The colval is a mixed color mode so different values can be input. 00589 \sa setColors, color 00590 */ 00591 function setColor( $colname, $colval ) 00592 { 00593 $this->Colors[$colname] = $colval; 00594 } 00595 00596 function hasImage( $dirs, $base, $md5Text, $alternativeText, $imageType ) 00597 { 00598 $name = preg_replace( array( "#[^a-zA-Z0-9_-]+#", 00599 "#__+#", 00600 "#_$#" ), 00601 array( '_', 00602 '_', 00603 '' ), 00604 $alternativeText ); 00605 $file = "$name.$imageType"; 00606 $splitMD5Path = eZDir::getPathFromFilename( $md5Text ); 00607 $filePath = eZDir::path( array( $dirs, $base, $splitMD5Path, $md5Text, $file ) ); 00608 00609 $fileHandler = eZClusterFileHandler::instance( $filePath ); 00610 return $fileHandler->exists(); 00611 } 00612 00613 function storeImage( $image, $dirs, $base, $md5Text, $alternativeText, $imageType ) 00614 { 00615 $name = preg_replace( array( "#[^a-zA-Z0-9_-]+#", 00616 "#__+#", 00617 "#_$#" ), 00618 array( '_', 00619 '_', 00620 '' ), 00621 $alternativeText ); 00622 $file = "$name.$imageType"; 00623 $splitMD5Path = eZDir::getPathFromFilename( $md5Text ); 00624 $dirPath = eZDir::path( array( $dirs, $base, $splitMD5Path, $md5Text ) ); 00625 $image->store( $file, $dirPath, $imageType ); 00626 00627 $fileHandler = eZClusterFileHandler::instance(); 00628 $filePath = eZDir::path( array( $dirPath, $file ) ); 00629 $mimeData = eZMimeType::findByURL( $filePath, true ); 00630 $fileHandler->fileStore( $filePath, 'texttoimage', false, $mimeData['name'] ); 00631 } 00632 00633 function setLoadImage( $image, $dirs, $base, $md5Text, $alternativeText, $imageType ) 00634 { 00635 $name = preg_replace( array( "#[^a-zA-Z0-9_-]+#", 00636 "#__+#", 00637 "#_$#" ), 00638 array( '_', 00639 '_', 00640 '' ), 00641 $alternativeText ); 00642 $file = "$name.$imageType"; 00643 $splitMD5Path = eZDir::getPathFromFilename( $md5Text ); 00644 $dirPath = eZDir::path( array( $dirs, $base, $splitMD5Path, $md5Text ) ); 00645 $filePath = eZDir::path( array( $dirPath, $file ) ); 00646 $fileHandler = eZClusterFileHandler::instance( $filePath ); 00647 if ( !$fileHandler->exists() ) 00648 { 00649 return null; 00650 } 00651 00652 // we use a local cache of the file, because the eZImage library only works on files on the file system 00653 $fileHandler->fetch( true ); 00654 $image->setStoredFile( $file, $dirPath, $imageType ); 00655 } 00656 00657 function loadImage( $dirs, $base, $md5Text, $alternativeText, $imageType ) 00658 { 00659 $name = preg_replace( array( "#[^a-zA-Z0-9_-]+#", 00660 "#__+#", 00661 "#_$#" ), 00662 array( '_', 00663 '_', 00664 '' ), 00665 $alternativeText ); 00666 $file = "$name.$imageType"; 00667 $splitMD5Path = eZDir::getPathFromFilename( $md5Text ); 00668 $dirPath = eZDir::path( array( $dirs, $base, $splitMD5Path, $md5Text ) ); 00669 $filePath = eZDir::path( array( $dirPath, $file ) ); 00670 00671 $fileHandler = eZClusterFileHandler::instance( $filePath ); 00672 if ( !$fileHandler->exists() ) 00673 { 00674 return null; 00675 } 00676 00677 // we use a local cache of the file, because the eZImage library only works on files on the file system 00678 $fileHandler->fetch( true ); 00679 return eZImageLayer::createForFile( $file, $dirPath, $this->StoreAs ); 00680 } 00681 00682 function readImageParameters( $tpl, $image, $operatorParameters, $rootNamespace, $currentNamespace, &$md5Input, &$alternativeText, 00683 $placement ) 00684 { 00685 $imageAlternativeText = false; 00686 foreach ( array_keys( $operatorParameters ) as $operatorParameterKey ) 00687 { 00688 $operatorParameter = $tpl->elementValue( $operatorParameters[$operatorParameterKey], $rootNamespace, $currentNamespace, $placement ); 00689 unset( $imageLayer ); 00690 $imageLayer = null; 00691 $imageParameters = array(); 00692 if ( is_string( $operatorParameter ) ) 00693 { 00694 $imageAlternativeText = $operatorParameter; 00695 } 00696 else if ( is_array( $operatorParameter ) ) 00697 { 00698 $imageLayer = $operatorParameter[0]; 00699 $imageParameterSource = $operatorParameter[1]; 00700 if ( isset( $imageParameterSource['transparency'] ) ) 00701 $imageParameters['transparency'] = $imageParameterSource['transparency']; 00702 if ( isset( $imageParameterSource['halign'] ) or 00703 isset( $imageParameterSource['valign'] ) or 00704 isset( $imageParameterSource['x'] ) or 00705 isset( $imageParameterSource['y'] ) ) 00706 { 00707 $xAlignment = eZImageObject::ALIGN_AXIS_NONE; 00708 $yAlignment = eZImageObject::ALIGN_AXIS_NONE; 00709 $xPlacement = eZImageObject::PLACE_CONSTANT; 00710 $yPlacement = eZImageObject::PLACE_CONSTANT; 00711 $xPos = 0; 00712 $yPos = 0; 00713 if ( isset( $imageParameterSource['halign'] ) ) 00714 { 00715 $alignmentText = strtolower( $imageParameterSource['halign'] ); 00716 switch ( $alignmentText ) 00717 { 00718 case 'left': 00719 { 00720 $xAlignment = eZImageObject::ALIGN_AXIS_START; 00721 } break; 00722 case 'right': 00723 { 00724 $xAlignment = eZImageObject::ALIGN_AXIS_STOP; 00725 } break; 00726 case 'center': 00727 { 00728 $xAlignment = eZImageObject::ALIGN_AXIS_CENTER; 00729 } break; 00730 } 00731 } 00732 if ( isset( $imageParameterSource['valign'] ) ) 00733 { 00734 $alignmentText = strtolower( $imageParameterSource['valign'] ); 00735 switch ( $alignmentText ) 00736 { 00737 case 'top': 00738 { 00739 $yAlignment = eZImageObject::ALIGN_AXIS_START; 00740 } break; 00741 case 'bottom': 00742 { 00743 $yAlignment = eZImageObject::ALIGN_AXIS_STOP; 00744 } break; 00745 case 'center': 00746 { 00747 $yAlignment = eZImageObject::ALIGN_AXIS_CENTER; 00748 } break; 00749 } 00750 } 00751 if ( isset( $imageParameterSource['x'] ) ) 00752 { 00753 $xPos = $imageParameterSource['x']; 00754 $xPlacement = eZImageObject::PLACE_CONSTANT; 00755 } 00756 if ( isset( $imageParameterSource['xrel'] ) ) 00757 { 00758 $xPos = $imageParameterSource['xrel']; 00759 $xPlacement = eZImageObject::PLACE_RELATIVE; 00760 } 00761 if ( isset( $imageParameterSource['y'] ) ) 00762 { 00763 $yPos = $imageParameterSource['y']; 00764 $yPlacement = eZImageObject::PLACE_CONSTANT; 00765 } 00766 if ( isset( $imageParameterSource['yrel'] ) ) 00767 { 00768 $yPos = $imageParameterSource['yrel']; 00769 $yPlacement = eZImageObject::PLACE_RELATIVE; 00770 } 00771 $x = array( 'alignment' => $xAlignment, 00772 'placement' => $xPlacement, 00773 'value' => $xPos ); 00774 $y = array( 'alignment' => $yAlignment, 00775 'placement' => $yPlacement, 00776 'value' => $yPos ); 00777 $imageParameters['x'] = $x; 00778 $imageParameters['y'] = $y; 00779 } 00780 } 00781 else 00782 $imageLayer = $operatorParameter; 00783 if ( $imageLayer !== null and 00784 $image->appendLayer( $imageLayer, $imageParameters ) ) 00785 { 00786 $layerText = trim( $imageLayer->alternativeText() ); 00787 if ( $layerText != '' ) 00788 { 00789 if ( $alternativeText != '' ) 00790 $alternativeText .= '-'; 00791 $alternativeText .= $layerText; 00792 } 00793 $md5Input .= $imageLayer->attribute( 'imagepath' ); 00794 $xAlignment = eZImageObject::ALIGN_AXIS_NONE; 00795 $yAlignment = eZImageObject::ALIGN_AXIS_NONE; 00796 $xPlacement = eZImageObject::PLACE_CONSTANT; 00797 $yPlacement = eZImageObject::PLACE_CONSTANT; 00798 $xPos = 0; 00799 $yPos = 0; 00800 if ( isset( $imageParameters['x']['alignment'] ) ) 00801 $xAlignment = $imageParameters['x']['alignment']; 00802 if ( isset( $imageParameters['y']['alignment'] ) ) 00803 $yAlignment = $imageParameters['y']['alignment']; 00804 if ( isset( $imageParameters['x']['placement'] ) ) 00805 $xPlacement = $imageParameters['x']['placement']; 00806 if ( isset( $imageParameters['y']['placement'] ) ) 00807 $yPlacement = $imageParameters['y']['placement']; 00808 if ( isset( $imageParameters['x']['value'] ) ) 00809 $xPos = $imageParameters['x']['value']; 00810 if ( isset( $imageParameters['y']['value'] ) ) 00811 $yPos = $imageParameters['y']['value']; 00812 $md5Input .= "$xPos-$xAlignment-$xPlacement-$yPos-$yAlignment-$yPlacement\n"; 00813 } 00814 } 00815 if ( $imageAlternativeText !== false ) 00816 $alternativeText = $imageAlternativeText; 00817 } 00818 00819 /// \privatesection 00820 /// The operator array 00821 public $Operators; 00822 /// The default class to use for text to image conversion 00823 public $DefaultClass; 00824 /// the directory were fonts are found, default is "" 00825 public $FontDir; 00826 /// the directory were cache files are created, default is "" 00827 public $CacheDir; 00828 /// the directory were html code finds the images, default is "" 00829 public $HTMLDir; 00830 /// the default font family, default is "arial" 00831 public $Family; 00832 /// the default font point size, default is 12 00833 public $PointSize; 00834 /// the default font angle, default is 0 00835 public $Angle; 00836 /// the default font x adjustment, default is 0 00837 public $XAdjust; 00838 /// the default font y adjustment, default is 0 00839 public $YAdjust; 00840 /// whether to reuse cache files or not 00841 public $UseCache; 00842 /// the color array, default is bgcolor=white and textcolor=black 00843 public $Colors; 00844 /// Whether image GD is supported 00845 public $ImageGDSupported; 00846 /// Storage Format, default is "png" 00847 public $StoreAs = 'png'; 00848 } 00849 00850 ?>