|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZImageInterface class 00004 // 00005 // Created on: <03-Oct-2002 15:05:09 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezimageinterface.php 00032 */ 00033 00034 /*! \defgroup eZImageObject Image object and layer handling */ 00035 00036 /*! 00037 \class eZImageInterface ezimageinterface.php 00038 \brief Base interface for all image object and layer classes 00039 00040 */ 00041 00042 class eZImageInterface 00043 { 00044 function eZImageInterface( $imageObjectRef = null, $imageObject = null, $width = false, $height = false ) 00045 { 00046 $this->ImageObjectRef = $imageObjectRef; 00047 $this->ImageObject = $imageObject; 00048 $this->Width = $width; 00049 $this->Height = $height; 00050 $this->AlternativeText = ''; 00051 $this->IsTrueColor = null; 00052 $this->Palette = array(); 00053 $this->PaletteIndex = array(); 00054 $this->StoredPath = false; 00055 $this->Font = null; 00056 $this->IsProcessed = false; 00057 } 00058 00059 /*! 00060 \return true if the image is true color. True color images behave differently from palette based 00061 and GD has problems with mixing the two types. 00062 */ 00063 function isTruecolor() 00064 { 00065 return $this->IsTrueColor; 00066 } 00067 00068 /*! 00069 \private 00070 \return a map array which maps from an attribute name to a member variable. 00071 Used by attributes, hasAttribute and attribute. 00072 */ 00073 function attributeMemberMap() 00074 { 00075 return array( 'filepath' => 'StoredPath', 00076 'filename' => 'StoredFile', 00077 'width' => 'Width', 00078 'height' => 'Height', 00079 'alternative_text' => 'AlternativeText' ); 00080 } 00081 00082 /*! 00083 \private 00084 \return a map array which maps from an attribute name to a member function. 00085 Used by attributes, hasAttribute and attribute. 00086 */ 00087 function attributeFunctionMap() 00088 { 00089 return array( 'imagepath' => 'imagePath', 00090 'has_size' => 'hasSize' ); 00091 } 00092 00093 /*! 00094 \return an array with attribute names which this object supports. 00095 */ 00096 function attributes() 00097 { 00098 return array_merge( array_keys( eZImageInterface::attributeMemberMap() ), 00099 array_keys( eZImageInterface::attributeFunctionMap() ) ); 00100 } 00101 00102 /*! 00103 \return true if the attribute \a $name exists. 00104 */ 00105 function hasAttribute( $name ) 00106 { 00107 $attributeMemberMap = eZImageInterface::attributeMemberMap(); 00108 if ( isset( $attributeMemberMap[$name] ) ) 00109 return true; 00110 $attributeFunctionMap = eZImageInterface::attributeFunctionMap(); 00111 if ( isset( $attributeFunctionMap[$name] ) ) 00112 return true; 00113 return false; 00114 } 00115 00116 /*! 00117 \return the attribute with name \a $name or \c null if the attribute does not exist. 00118 */ 00119 function attribute( $name ) 00120 { 00121 $attributeMemberMap = eZImageInterface::attributeMemberMap(); 00122 if ( isset( $attributeMemberMap[$name] ) ) 00123 { 00124 $member = $attributeMemberMap[$name]; 00125 if ( isset( $this->$member ) ) 00126 return $this->$member; 00127 eZDebug::writeWarning( 'The member variable $member was not found for attribute $name', 'eZImageInterface::attribute' ); 00128 return null; 00129 } 00130 $attributeFunctionMap = eZImageInterface::attributeFunctionMap(); 00131 if ( isset( $attributeFunctionMap[$name] ) ) 00132 { 00133 $function = $attributeFunctionMap[$name]; 00134 if ( method_exists( $this, $function ) ) 00135 return $this->$function(); 00136 eZDebug::writeWarning( 'The member function $function was not found for attribute $name', 'eZImageInterface::attribute' ); 00137 return null; 00138 } 00139 eZDebug::writeError( "Attribute '$name' does not exist", 'eZImageInterface::attribute' ); 00140 return null; 00141 } 00142 00143 /*! 00144 \return true if the image object has been processed, this means that 00145 image has been rendered. 00146 */ 00147 function isProcessed() 00148 { 00149 return $this->IsProcessed; 00150 } 00151 00152 /*! 00153 \return true if the width and height of the image has been set. 00154 */ 00155 function &hasSize() 00156 { 00157 $hasSize = ( $this->Width !== false and $this->Height !== false ); 00158 return $hasSize; 00159 } 00160 00161 /*! 00162 \return the path to the image file including the file. 00163 */ 00164 function &imagePath() 00165 { 00166 $imagePath = $this->StoredPath . '/' . $this->StoredFile; 00167 return $imagePath; 00168 } 00169 00170 /*! 00171 Sets the alternative text to \a $text, it will be used for describing the 00172 image and can be used by browsers that cannot view images. 00173 */ 00174 function setAlternativeText( $text ) 00175 { 00176 $this->AlternativeText = $text; 00177 } 00178 00179 /*! 00180 \return the alternative text for the image. 00181 \sa setAlternativeText 00182 */ 00183 function alternativeText() 00184 { 00185 return $this->AlternativeText; 00186 } 00187 00188 /*! 00189 \protected 00190 Registers the GD image object \a $image for destruction upon script end. 00191 This makes sure that image resources are cleaned up after use. 00192 \return a reference for the image which can be used in unregisterImage later on. Returns false if resource can't be registered. 00193 */ 00194 static function registerImage( $image ) 00195 { 00196 if ( !is_resource( $image ) or get_resource_type( $image ) != 'gd' ) 00197 return false; 00198 $imageObjectRef = md5( microtime() ); 00199 $createdImageArray =& $GLOBALS['eZImageCreatedArray']; 00200 if ( !is_array( $createdImageArray ) ) 00201 { 00202 $createdImageArray = array(); 00203 register_shutdown_function( 'eZGlobalImageCleanupFunction' ); 00204 } 00205 $createdImageArray[$imageObjectRef] = $image; 00206 return $imageObjectRef; 00207 } 00208 00209 /*! 00210 Tries to unregister the image with reference \a $imageRef 00211 */ 00212 static function unregisterImage( $imageRef ) 00213 { 00214 $createdImageArray =& $GLOBALS['eZImageCreatedArray']; 00215 if ( !is_array( $createdImageArray ) ) 00216 return; 00217 if ( !isset( $createdImageArray[$imageRef] ) ) 00218 return; 00219 unset( $createdImageArray[$imageRef] ); 00220 } 00221 00222 /*! 00223 Cleans up all registered images. 00224 */ 00225 static function cleanupRegisteredImages() 00226 { 00227 $createdImageArray =& $GLOBALS['eZImageCreatedArray']; 00228 if ( !is_array( $createdImageArray ) ) 00229 return; 00230 foreach ( array_keys( $createdImageArray ) as $createImageKey ) 00231 { 00232 $createdImage = $createdImageArray[$createImageKey]; 00233 if ( is_resource( $createdImage ) and get_resource_type( $createdImage ) == 'gd' ) 00234 ImageDestroy( $createdImage ); 00235 } 00236 } 00237 00238 /*! 00239 Tries to load the PNG image from the path \a $storedPath and file \a $storedFile into 00240 the current image object. 00241 \return true if succesful. 00242 */ 00243 function loadPNG( $storedPath, $storedFile ) 00244 { 00245 if ( !function_exists( 'ImageCreateFromPNG' ) ) 00246 return false; 00247 $this->ImageObject = ImageCreateFromPNG( $storedPath . '/' . $storedFile ); 00248 if ( $this->ImageObject ) 00249 { 00250 $this->ImageObjectRef = eZImageInterface::registerImage( $this->ImageObject ); 00251 return true; 00252 } 00253 return false; 00254 } 00255 00256 /*! 00257 Tries to load the JPEG image from the path \a $storedPath and file \a $storedFile into 00258 the current image object. 00259 \return true if succesful. 00260 */ 00261 function loadJPEG( $storedPath, $storedFile ) 00262 { 00263 $this->ImageObject = ImageCreateFromJPEG( $storedPath . '/' . $storedFile ); 00264 if ( $this->ImageObject ) 00265 { 00266 $this->ImageObjectRef = eZImageInterface::registerImage( $this->ImageObject ); 00267 return true; 00268 } 00269 return false; 00270 } 00271 00272 /*! 00273 Tries to load the GIF image from the path \a $storedPath and file \a $storedFile into 00274 the current image object. 00275 \return true if succesful. 00276 */ 00277 function loadGIF( $storedPath, $storedFile ) 00278 { 00279 if ( !function_exists( 'ImageCreateFromGIF' ) ) 00280 return false; 00281 $this->ImageObject = ImageCreateFromGIF( $storedPath . '/' . $storedFile ); 00282 if ( $this->ImageObject ) 00283 { 00284 $this->ImageObjectRef = eZImageInterface::registerImage( $this->ImageObject ); 00285 return true; 00286 } 00287 return false; 00288 } 00289 00290 /*! 00291 Tries to load the stored image set by setStoredFile(). 00292 If the stored type is not set it will try all formats until one succeeds. 00293 \return true if succesful. 00294 */ 00295 function load() 00296 { 00297 if ( $this->ImageObject !== null and 00298 $this->ImageObjectRef !== null ) 00299 return; 00300 switch( $this->StoredType ) 00301 { 00302 case 'png': 00303 { 00304 return $this->loadPNG( $this->StoredPath, $this->StoredFile ); 00305 } break; 00306 00307 case 'jpg': 00308 { 00309 return $this->loadJPEG( $this->StoredPath, $this->StoredFile ); 00310 } break; 00311 00312 case 'gif': 00313 { 00314 return $this->loadGIF( $this->StoredPath, $this->StoredFile ); 00315 } break; 00316 00317 default: 00318 { 00319 if ( @$this->loadPNG( $this->StoredPath, $this->StoredFile ) ) 00320 return true; 00321 else if ( @$this->loadJPEG( $this->StoredPath, $this->StoredFile ) ) 00322 return true; 00323 else if ( @$this->loadGIF( $this->StoredPath, $this->StoredFile ) ) 00324 return true; 00325 eZDebug::writeError( 'Image format not supported: ' . $this->StoredType, 'eZImageInterface::load' ); 00326 }; 00327 } 00328 return false; 00329 } 00330 00331 /*! 00332 Cleans up the current image object if it is set. 00333 */ 00334 function destroy() 00335 { 00336 if ( $this->ImageObjectRef === null ) 00337 return; 00338 if ( is_resource( $this->ImageObject ) and get_resource_type( $this->ImageObject ) == 'gd' ) 00339 ImageDestroy( $this->ImageObject ); 00340 eZImageInterface::unregisterImage( $this->ImageObjectRef ); 00341 unset( $this->ImageObject ); 00342 $this->ImageObject = null; 00343 $this->ImageObjectRef = null; 00344 } 00345 00346 /*! 00347 \return the current image object, if \a $createMissing is true if will 00348 run the image processing to make sure it is created. 00349 Returns \c null if no image is available. 00350 \sa imageObjectInternal 00351 */ 00352 function imageObject( $createMissing = true ) 00353 { 00354 if ( $this->ImageObject === null or 00355 $this->ImageObjectRef === null ) 00356 { 00357 if ( $createMissing ) 00358 { 00359 if ( $this->StoredFile != '' ) 00360 { 00361 $this->process(); 00362 } 00363 } 00364 } 00365 return $this->ImageObject; 00366 } 00367 00368 /*! 00369 \protected 00370 \return the current image object, will create an empty image object if \a $createMissing 00371 is true and the image object is not already created. 00372 \sa imageObject 00373 */ 00374 function imageObjectInternal( $createMissing = true ) 00375 { 00376 if ( $this->ImageObject === null or 00377 $this->ImageObjectRef === null ) 00378 { 00379 if ( $createMissing ) 00380 $this->create( $this->Width, $this->Height ); 00381 } 00382 return $this->ImageObject; 00383 } 00384 00385 /*! 00386 Makes sure the image object is processed and rendered. 00387 Calls processImage() which is implemented by all descendants of this class to do the real work. 00388 */ 00389 function process() 00390 { 00391 if ( $this->processImage() ) 00392 $this->IsProcessed = true; 00393 } 00394 00395 /*! 00396 \virtual 00397 Tries to render an image onto the image object, each inheriting class must override this to do 00398 somethign sensible. By default it will try to load the stored image if one is set. 00399 \return true if the image was succesfully processed. 00400 */ 00401 function processImage() 00402 { 00403 if ( $this->StoredFile == '' ) 00404 return true; 00405 $fileArray = array( $this->StoredPath, $this->StoredFile ); 00406 //include_once( 'lib/ezfile/classes/ezdir.php' ); 00407 $filePath = eZDir::path( $fileArray ); 00408 $imageinfo = getimagesize( $filePath ); 00409 if ( $imageinfo ) 00410 { 00411 $width = $imageinfo[0]; 00412 $height = $imageinfo[1]; 00413 if ( $this->load() ) 00414 { 00415 $this->Width = $width; 00416 $this->Height = $height; 00417 return true; 00418 } 00419 else 00420 eZDebug::writeWarning( "Image failed to load '$filePath'", 'eZImageInterface::imageObject' ); 00421 } 00422 else 00423 eZDebug::writeWarning( "No image info could be extracted from '$filePath'", 'eZImageInterface::imageObject' ); 00424 return false; 00425 } 00426 00427 /*! 00428 Stores the current image object to disk, the image is stored in the path \a $filePath with filename \a $fileName. 00429 The parameter \a $type determines the image format, supported are \c png and \c jpg. 00430 \return true if the image was stored correctly. 00431 */ 00432 function store( $fileName, $filePath, $type ) 00433 { 00434 if ( !$this->IsProcessed ) 00435 $this->process(); 00436 $imageObject = $this->imageObject(); 00437 switch( $type ) 00438 { 00439 case 'png': 00440 { 00441 //include_once( 'lib/ezfile/classes/ezdir.php' ); 00442 if ( !file_exists( $filePath ) ) 00443 { 00444 eZDir::mkdir( $filePath, false, true ); 00445 } 00446 $fileFullPath = eZDir::path( array( $filePath, $fileName ) ); 00447 ImagePNG( $imageObject, $fileFullPath ); 00448 $this->StoredPath = $filePath; 00449 $this->StoredFile = $fileName; 00450 $this->StoredType = $type; 00451 return true; 00452 } break; 00453 00454 case 'jpg': 00455 { 00456 //include_once( 'lib/ezfile/classes/ezdir.php' ); 00457 if ( !file_exists( $filePath ) ) 00458 { 00459 eZDir::mkdir( $filePath, false, true ); 00460 } 00461 ImageJPEG( $imageObject, eZDir::path( array( $filePath, $fileName ) ) ); 00462 $this->StoredPath = $filePath; 00463 $this->StoredFile = $fileName; 00464 $this->StoredType = $type; 00465 return true; 00466 } break; 00467 00468 default: 00469 { 00470 eZDebug::writeError( 'Image format not supported: ' . $type, 'eZImageInterface::store' ); 00471 }; 00472 } 00473 return false; 00474 } 00475 00476 /*! 00477 \static 00478 \return true if GD2 is installed. 00479 */ 00480 static function hasGD2() 00481 { 00482 $imageINI = eZINI::instance( 'image.ini' ); 00483 return $imageINI->variable( 'GDSettings', 'HasGD2' ) == 'true'; 00484 // $testGD = get_extension_funcs( "gd" ); // Grab function list 00485 // if ( !$testGD ) 00486 // { 00487 // // echo "GD not even installed."; 00488 // return false; 00489 // } 00490 // if ( in_array( "imagegd2", 00491 // $testGD ) ) 00492 // return true; 00493 // return false; 00494 } 00495 00496 /*! 00497 \static 00498 \private 00499 Creates an image with size \a $width and \a $height using GD and returns it. 00500 */ 00501 static function createImage( $width, $height, &$useTruecolor ) 00502 { 00503 if ( $useTruecolor === null ) 00504 { 00505 // print( "has GD2='" . eZImageInterface::hasGD2() . "'<br/>" ); 00506 $useTruecolor = eZImageInterface::hasGD2(); 00507 } 00508 if ( $useTruecolor and 00509 !function_exists( 'ImageCreateTrueColor' ) ) 00510 { 00511 eZDebug::writeWarning( 'Function ImageCreateTrueColor does not exist, cannot create true color images', 00512 'eZImageInterface::createImage' ); 00513 $useTruecolor = false; 00514 } 00515 if ( $useTruecolor ) 00516 $imageObject = ImageCreateTrueColor( $width, $height ); 00517 else 00518 $imageObject = ImageCreate( $width, $height ); 00519 return $imageObject; 00520 } 00521 00522 /*! 00523 Creates a new image object with width \a $width and height \a $height. 00524 \a $useTruecolor determines the type of image, if \c true it will be truecolor, 00525 if \c false it will be palette based or if \c null it will create it depending on 00526 the GD version. GD 2 will get truecolor while < 2 will get palette based. 00527 */ 00528 function create( $width, $height, $useTruecolor = null ) 00529 { 00530 if ( $this->ImageObject !== null and 00531 $this->ImageObjectRef !== null ) 00532 { 00533 $this->destroy(); 00534 } 00535 unset( $this->ImageObject ); 00536 $this->ImageObject = eZImageInterface::createImage( $width, $height, $useTruecolor ); 00537 $this->Width = $width; 00538 $this->Height = $height; 00539 // eZDebug::writeDebug( $this->ImageObject, 'create' ); 00540 $this->IsTrueColor = $useTruecolor; 00541 $this->ImageObjectRef = eZImageInterface::registerImage( $this->ImageObject ); 00542 } 00543 00544 /*! 00545 Copies the image from \a $image as the current image object. 00546 */ 00547 function __clone() 00548 { 00549 $this->cloneImage( $this->imageObject(), $this->width(), $this->height(), 00550 $this->isTruecolor() ); 00551 } 00552 00553 /*! 00554 Clones the image object \a $imageObject with width \a $width, height \a $height 00555 and truecolor settings \a $useTruecolor. 00556 */ 00557 function cloneImage( $imageObject, $width, $height, $useTruecolor = null ) 00558 { 00559 if ( $this->ImageObject !== null and 00560 $this->ImageObjectRef !== null ) 00561 { 00562 $this->destroy(); 00563 } 00564 $this->ImageObject = eZImageInterface::createImage( $width, $height, $useTruecolor ); 00565 $this->IsTrueColor = $useTruecolor; 00566 $this->ImageObjectRef = eZImageInterface::registerImage( $this->ImageObject ); 00567 ImageCopy( $this->ImageObject, $imageObject, 0, 0, 0, 0, $width, $height ); 00568 } 00569 00570 /*! 00571 \return the current width of the image or \a false if no size has been set. 00572 */ 00573 function width() 00574 { 00575 return $this->Width; 00576 } 00577 00578 /*! 00579 \return the current height of the image or \a false if no size has been set. 00580 */ 00581 function height() 00582 { 00583 return $this->Height; 00584 } 00585 00586 /*! 00587 Sets the width of the image to \a $w. 00588 */ 00589 function setWidth( $w ) 00590 { 00591 $this->Width = $w; 00592 } 00593 00594 /*! 00595 Sets the height of the image to \a $h. 00596 */ 00597 function setHeight( $h ) 00598 { 00599 $this->Height = $h; 00600 } 00601 00602 /*! 00603 Sets the path, file and type of the stored file. 00604 These settings will be used by load(). 00605 */ 00606 function setStoredFile( $file, $path, $type ) 00607 { 00608 $this->StoredFile = $file; 00609 $this->StoredPath = $path; 00610 $this->StoredType = $type; 00611 } 00612 00613 /*! 00614 Sets the current font object to \a $font. 00615 */ 00616 function setFont( $font ) 00617 { 00618 $this->Font = $font; 00619 } 00620 00621 /*! 00622 \return the current font object or \c null if not font object has been set. 00623 */ 00624 function font() 00625 { 00626 return $this->Font; 00627 } 00628 00629 /*! 00630 Copies the image \a $imageObject with size \a $sourceWidth and \a $sourceHeight 00631 and position \a $sourceX and \a $sourceY onto the destination image \a $destinationImageObject 00632 at position \a $destinationX and \a $destinationY. 00633 */ 00634 function copyImage( $destinationImageObject, $imageObject, 00635 $destinationX, $destinationY, 00636 $sourceWidth, $sourceHeight, $sourceX = 0, $sourceY = 0 ) 00637 { 00638 ImageCopy( $destinationImageObject, $imageObject, 00639 $destinationX, $destinationY, 00640 $sourceX, $sourceY, $sourceWidth, $sourceHeight ); 00641 } 00642 00643 /*! 00644 Merges the image \a $imageObject with size \a $sourceWidth and \a $sourceHeight 00645 and position \a $sourceX and \a $sourceY with the destination image \a $destinationImageObject 00646 at position \a $destinationX and \a $destinationY. 00647 The merged image is placed on the \a $destinationImageObject. 00648 \param $transparency determines how transparent the source image is. 0 is the same as copyImage 00649 and 100 is the same is no copy is made. 00650 */ 00651 function mergeImage( $destinationImageObject, $imageObject, 00652 $destinationX, $destinationY, 00653 $sourceWidth, $sourceHeight, $sourceX = 0, $sourceY = 0, 00654 $transparency = 0 ) 00655 { 00656 $percent = 100 - $transparency; 00657 ImageCopyMerge( $destinationImageObject, $imageObject, 00658 $destinationX, $destinationY, 00659 $sourceX, $sourceY, $sourceWidth, $sourceHeight, 00660 $percent ); 00661 } 00662 00663 /*! 00664 Alpha blends the image \a $imageObject with size \a $sourceWidth and \a $sourceHeight 00665 and position \a $sourceX and \a $sourceY onto the destination image \a $destinationImageObject 00666 at position \a $destinationX and \a $destinationY. 00667 \note This required GD2 and uses color 0 (black) for blending. 00668 */ 00669 function blendImage( $destinationImageObject, $imageObject, 00670 $destinationX, $destinationY, 00671 $sourceWidth, $sourceHeight, $sourceX = 0, $sourceY = 0 ) 00672 { 00673 ImageAlphaBlending( $destinationImageObject, true ); 00674 ImageCopy( $destinationImageObject, $imageObject, 00675 $destinationX, $destinationY, 00676 $sourceX, $sourceY, $sourceWidth, $sourceHeight ); 00677 } 00678 00679 function merge( $imageObject, $x, $y, $width, $height ) 00680 { 00681 if ( $this->ImageObject === null or 00682 $this->ImageObjectRef === null ) 00683 return false; 00684 // ImageAlphaBlending( $this->ImageObject, true ); 00685 imagecolortransparent( $imageObject, 0 ); 00686 // ImageCopy( $this->ImageObject, $imageObject, $x, $y, 0, 0, $width, $height ); 00687 ImageCopyMerge( $this->ImageObject, $imageObject, $x, $y, 0, 0, $width, $height, 50 ); 00688 } 00689 00690 /*! 00691 Clears the image object with color \a $color. 00692 If \a $color is not specified it will use the first color set. 00693 */ 00694 function clear( $color = false ) 00695 { 00696 if ( $color === false ) 00697 { 00698 if ( count( $this->PaletteIndex ) > 0) 00699 $color = $this->PaletteIndex[0]; 00700 else 00701 $color = 'bgcol'; 00702 } 00703 if ( is_string( $color ) ) 00704 $color = $this->color( $color ); 00705 ImageFilledRectangle( $this->ImageObject, 0, 0, $this->Width, $this->Height, $color ); 00706 } 00707 00708 /*! 00709 Allocates the color \a $red, \a $green and \a $blue with name \a $name and returns it. 00710 Will return the palette index for palette based images and the color value for true color. 00711 */ 00712 function allocateColor( $name, $red, $green, $blue ) 00713 { 00714 if ( isset( $this->Palette[$name] ) ) 00715 { 00716 eZDebug::writeError( 'Color already defined: ' . $name, 'eZImageInterface::allocateColor' ); 00717 return null; 00718 } 00719 $red = max( 0, min( 255, $red ) ); 00720 $green = max( 0, min( 255, $green ) ); 00721 $blue = max( 0, min( 255, $blue ) ); 00722 $color = ImageColorAllocate( $this->ImageObject, $red, $green, $blue ); 00723 $this->Palette[$name] = $color; 00724 $this->PaletteIndex[] = $color; 00725 return $color; 00726 } 00727 00728 /*! 00729 \return the color for the name \a $name. 00730 */ 00731 function color( $name ) 00732 { 00733 if ( !isset( $this->Palette[$name] ) ) 00734 { 00735 eZDebug::writeError( 'Color not defined: ' . $name, 'eZImageInterface::color' ); 00736 return null; 00737 } 00738 return $this->Palette[$name]; 00739 } 00740 00741 /*! 00742 \return the color used for text drawing. 00743 */ 00744 function textColor() 00745 { 00746 return $this->TextColor; 00747 } 00748 00749 /*! 00750 Sets the color used for text drawing to \a $textColor. 00751 */ 00752 function setTextColor( $textColor ) 00753 { 00754 $this->TextColor = $textColor; 00755 } 00756 00757 /*! 00758 Draws the text \a $text using the font \a $font and color \a $textColor 00759 at position \a $x and \a $y with angle \a $angle. 00760 If \a $imageObject is specified it will use that for drawing instead of 00761 the current image. 00762 */ 00763 function drawText( &$font, $textColor, $text, $x, $y, $angle, 00764 $imageObject = null ) 00765 { 00766 if ( !$font ) 00767 { 00768 eZDebug::writeWarning( 'Cannot render text, no font is set', 00769 'eZImageInterface::drawText' ); 00770 return false; 00771 } 00772 if ( !$textColor ) 00773 { 00774 eZDebug::writeWarning( 'Cannot render text, no text color is set', 00775 'eZImageInterface::drawText' ); 00776 return false; 00777 } 00778 if ( is_string( $textColor ) ) 00779 $textColor = $this->color( $textColor ); 00780 if ( $textColor === null ) 00781 { 00782 eZDebug::writeWarning( 'Cannot render text, invalid text color', 00783 'eZImageInterface::drawText' ); 00784 return false; 00785 } 00786 00787 $x += $font->xAdjustment(); 00788 $y += $font->yAdjustment(); 00789 00790 if ( $imageObject === null ) 00791 $imageObject = $this->ImageObject; 00792 00793 ImageTTFText( $imageObject, $font->pointSize(), $angle, $x, $y, 00794 $textColor, $font->realFile(), $text ); 00795 } 00796 00797 /// \privatesection 00798 public $Width; 00799 public $Height; 00800 public $Font; 00801 public $ImageObject; 00802 public $ImageObjectRef; 00803 public $StoredFile; 00804 public $StoredPath; 00805 public $StoredType; 00806 public $PaletteIndex; 00807 public $Palette; 00808 public $AlternativeText; 00809 public $IsTrueColor; 00810 public $IsProcessed; 00811 } 00812 00813 /*! 00814 Global function for eZImageInterface. It will be called at the end of the script execution 00815 and will cleanup all images left behind. 00816 */ 00817 function eZGlobalImageCleanupFunction() 00818 { 00819 eZImageInterface::cleanupRegisteredImages(); 00820 } 00821 00822 ?>