00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 include_once( 'lib/ezimage/classes/ezimagehandler.php' );
00047
00048 class eZImageGDHandler extends eZImageHandler
00049 {
00050
00051
00052
00053 function eZImageGDHandler( $handlerName, $isGloballyEnabled,
00054 $outputRewriteType = EZ_IMAGE_HANDLER_REPLACE_SUFFIX,
00055 $conversionRules = false )
00056 {
00057 $supportedInputMIMETypes = array();
00058 $supportedOutputMIMETypes = array();
00059 $this->InputMap = array();
00060 $this->OutputMap = array();
00061 $this->OutputQualityMap = array();
00062 $isEnabled = false;
00063 if ( function_exists( "imagetypes" ) )
00064 {
00065 $gdFunctions = array( array( 'mimetype' => 'image/gif',
00066 'input' => 'imagecreatefromgif',
00067 'output' => 'imagegif' ),
00068 array( 'mimetype' => 'image/vnd.wap.wbmp',
00069 'input' => 'imagecreatefromwbmp',
00070 'output' => 'imagewbmp' ),
00071 array( 'mimetype' => 'image/png',
00072 'input' => 'imagecreatefrompng',
00073 'output' => 'imagepng' ),
00074 array( 'mimetype' => 'image/jpeg',
00075 'input' => 'imagecreatefromjpeg',
00076 'output' => 'imagejpeg',
00077 'qualityparameter' => true ) );
00078 foreach ( $gdFunctions as $gdFunction )
00079 {
00080 $inputFunction = $gdFunction['input'];
00081 $outputFunction = $gdFunction['output'];
00082 if ( function_exists( $inputFunction ) or function_exists( $outputFunction ) )
00083 {
00084 $isEnabled = true;
00085 $mimeType = $gdFunction['mimetype'];
00086 if ( function_exists( $inputFunction ) )
00087 {
00088 $supportedInputMIMETypes[] = $mimeType;
00089 $this->InputMap[$mimeType] = $inputFunction;
00090 }
00091 if ( function_exists( $outputFunction ) )
00092 {
00093 $this->OutputMap[$mimeType] = $outputFunction;
00094 $supportedOutputMIMETypes[] = $mimeType;
00095 }
00096 if ( isset( $gdFunction['qualityparameter'] ) )
00097 $this->OutputQualityMap[$mimeType] = $gdFunction['qualityparameter'];
00098 else
00099 $this->OutputQualityMap[$mimeType] = false;
00100 }
00101 }
00102 }
00103 if ( !$isGloballyEnabled )
00104 $isEnabled = false;
00105 $this->FilterFunctionMap = array( 'geometry/scale' => 'scaleImage',
00106 'geometry/scalewidth' => 'scaleImageWidth',
00107 'geometry/scaleheight' => 'scaleImageHeight',
00108 'geometry/scaledownonly' => 'scaleImageDownOnly',
00109 'geometry/scalewidthdownonly' => 'scaleImageWidthDownOnly',
00110 'geometry/scaleheightdownonly' => 'scaleImageHeightDownOnly',
00111 'geometry/scaleexact' => 'scaleImageExact',
00112 'geometry/scalepercent' => 'scaleImagePercent',
00113 'geometry/crop' => 'cropImage',
00114 'colorspace/gray' => 'setImageColorspaceGray',
00115 'luminance' => 'setImageLuminance',
00116 'luminance/gray' => 'setImageLuminanceNamed',
00117 'luminance/sepia' => 'setImageLuminanceNamed',
00118 'color/monochrome' => 'setImageColorThresholdName',
00119 'border' => 'createImageBorder',
00120 'border/color' => 'setImageBorderColor',
00121 'border/width' => 'setImageBorderWidth' );
00122 $this->LuminanceColorScales = array( 'luminance/gray' => array( 1.0, 1.0, 1.0 ),
00123 'luminance/sepia' => array( 1.0, 0.89, 0.74 ) );
00124 $this->ThresholdList = array( 'color/monochrome' => array( array( 'threshold' => 127,
00125 'rgb' => array( 0, 0, 0 ) ),
00126 array( 'threshold' => 255,
00127 'rgb' => array( 255, 255, 255 ) ) ) );
00128
00129 $filters = array();
00130 foreach ( $this->FilterFunctionMap as $filterName => $filterFunction )
00131 {
00132 $filters[] = array( 'name' => $filterName );
00133 }
00134 $this->eZImageHandler( $handlerName, $isEnabled,
00135 $outputRewriteType,
00136 $supportedInputMIMETypes, $supportedOutputMIMETypes,
00137 $conversionRules, $filters );
00138 }
00139
00140
00141
00142
00143 function convert( &$manager, $sourceMimeData, &$destinationMimeData, $filters = false )
00144 {
00145 $sourceMimeType = $sourceMimeData['name'];
00146 $destinationMimeType = $destinationMimeData['name'];
00147 if ( !isset( $this->InputMap[$sourceMimeType] ) )
00148 {
00149 eZDebug::writeError( "MIME-Type $sourceMimeType is not supported as input by GD converter",
00150 'eZImageGDHandler::convert' );
00151 return false;
00152 }
00153 if ( !isset( $this->OutputMap[$destinationMimeType] ) )
00154 {
00155 eZDebug::writeError( "MIME-Type $destinationMimeType is not supported as output by GD converter",
00156 'eZImageGDHandler::convert' );
00157 return false;
00158 }
00159
00160 $inputFunction = $this->InputMap[$sourceMimeType];
00161 $outputFunction = $this->OutputMap[$destinationMimeType];
00162 $outputQualityParameter = $this->OutputQualityMap[$destinationMimeType];
00163 $inputFile = $sourceMimeData['url'];
00164 $outputFile = $destinationMimeData['url'];
00165
00166 if ( !file_exists( $inputFile ) )
00167 {
00168 eZDebug::writeError( "Source image $inputFile does not exist, cannot convert",
00169 'eZImageGDHandler::convert' );
00170 return false;
00171 }
00172 $inputImage = $inputFunction( $inputFile );
00173
00174 $currentImage =& $inputImage;
00175
00176 $filterVariables = array( 'border-color' => array( 127, 127, 127 ),
00177 'border-size' => array( 0, 0 ) );
00178
00179 if ( $filters !== false )
00180 {
00181 foreach ( $filters as $filterData )
00182 {
00183 $filterName = $filterData['name'];
00184 if ( isset( $this->FilterFunctionMap[$filterName] ) )
00185 {
00186 $filterFunction = $this->FilterFunctionMap[$filterName];
00187 $filteredImage =& $this->$filterFunction( $currentImage, $filterData, $filterVariables, $sourceMimeData, $destinationMimeData );
00188 if ( $filteredImage !== false )
00189 {
00190 if ( $filteredImage != $currentImage )
00191 {
00192 ImageDestroy( $currentImage );
00193 }
00194 $currentImage =& $filteredImage;
00195 }
00196 }
00197 }
00198 }
00199
00200 $outputImage =& $currentImage;
00201
00202 if ( $outputImage )
00203 {
00204 $outputQuality = false;
00205 if ( $outputQualityParameter )
00206 $outputQuality = $manager->qualityValue( $destinationMimeType );
00207 if ( $outputQuality !== false )
00208 {
00209 $returnCode = $outputFunction( $outputImage, $outputFile, $outputQuality );
00210 }
00211 else
00212 {
00213 $returnCode = $outputFunction( $outputImage, $outputFile );
00214 }
00215
00216 ImageDestroy( $outputImage );
00217 }
00218 else
00219 $returnCode = false;
00220
00221 if ( $returnCode )
00222 {
00223 if ( !file_exists( $destinationMimeData['url'] ) )
00224 {
00225 eZDebug::writeError( "Unknown destination file: " . $destinationMimeData['url'], "eZImageGDHandler(" . $this->HandlerName . ")" );
00226 return false;
00227 }
00228 $this->changeFilePermissions( $destinationMimeData['url'] );
00229 return true;
00230 }
00231 else
00232 {
00233 eZDebug::writeWarning( "Failed converting $inputFile ($sourceMimeType) to $outputFile ($destinationMimeType)", 'eZImageGDHandler::convert' );
00234 return false;
00235 }
00236 }
00237
00238 function setImageBorderColor( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00239 {
00240 $filterVariables['border-color'] = $filterData['data'];
00241 return false;
00242 }
00243
00244 function setImageBorderWidth( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00245 {
00246 $filterVariables['border-size'] = array( $filterData['data'][0], $filterData['data'][0] );
00247 return $this->createImageBorder( $imageObject, $filterData, $filterVariables, $sourceMimeData, $destinationMimeData );
00248 }
00249
00250 function &setImageBorder( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00251 {
00252 $filterVariables['border-size'] = array( $filterData['data'][0], $filterData['data'][1] );
00253 return $this->createImageBorder( $imageObject, $filterData, $filterVariables, $sourceMimeData, $destinationMimeData );
00254 }
00255
00256 function &createImageBorder( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00257 {
00258 $width = ImageSX( $imageObject );
00259 $height = ImageSY( $imageObject );
00260 $borderWidth = $filterVariables['border-size'][0];
00261 $borderHeight = $filterVariables['border-size'][1];
00262 $borderColor = $filterVariables['border-color'];
00263 $newWidth = $width + $borderWidth*2;
00264 $newHeight = $height + $borderHeight*2;
00265
00266 $temporaryImageObject =& $this->imageCopy( $imageObject,
00267 $this->createGeometry( $newWidth, $newHeight, $borderWidth, $borderHeight ),
00268 $this->createGeometry( $width, $height, 0, 0 ),
00269 $sourceMimeData, $destinationMimeData );
00270 $color = ImageColorAllocate( $temporaryImageObject, $borderColor[0], $borderColor[1], $borderColor[2] );
00271 ImageFilledRectangle( $temporaryImageObject, 0, 0, $newWidth, $borderHeight, $color );
00272 ImageFilledRectangle( $temporaryImageObject, $newWidth - $borderWidth, 0, $newWidth, $newHeight, $color );
00273 ImageFilledRectangle( $temporaryImageObject, 0, $newHeight - $borderHeight, $newWidth, $newHeight, $color );
00274 ImageFilledRectangle( $temporaryImageObject, 0, 0, $borderWidth, $newHeight, $color );
00275 return $temporaryImageObject;
00276 }
00277
00278
00279
00280
00281 function &setImageColorspaceGray( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00282 {
00283 $colorScale = array( 1.0, 1.0, 1.0 );
00284 return $this->setImageLuminanceColorScale( $imageObject, $filterData, $sourceMimeData, $destinationMimeData,
00285 $colorScale );
00286 }
00287
00288
00289
00290
00291
00292 function &setImageLuminance( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00293 {
00294 $colorScale = $filterData['data'];
00295 return $this->setImageLuminanceColorScale( $imageObject, $filterData, $sourceMimeData, $destinationMimeData,
00296 $colorScale );
00297 }
00298
00299
00300
00301
00302
00303 function &setImageLuminanceNamed( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00304 {
00305 if ( isset( $this->LuminanceColorScales[$filterData['name']] ) )
00306 {
00307 $colorScale = $this->LuminanceColorScales[$filterData['name']];
00308 }
00309 else
00310 {
00311 eZDebug::writeDebug( "No luminance scale named " . $filterData['name'] . ", applying gray scales",
00312 'eZImageGDHandler::setImageLuminanceName' );
00313 $colorScale = array( 1.0, 1.0, 1.0 );
00314 }
00315 return $this->setImageLuminanceColorScale( $imageObject, $filterData, $sourceMimeData, $destinationMimeData,
00316 $colorScale );
00317 }
00318
00319
00320
00321
00322
00323 function &setImageLuminanceColorScale( &$imageObject, $filterData, $sourceMimeData, $destinationMimeData,
00324 $colorScale )
00325 {
00326 $white = ImageColorAllocate( $imageObject, 255, 255, 255 );
00327 $black = ImageColorAllocate( $imageObject, 0, 0, 0 );
00328
00329 $rmod = $colorScale[0];
00330 $gmod = $colorScale[1];
00331 $bmod = $colorScale[2];
00332
00333 $width = ImageSX( $imageObject );
00334 $height = ImageSY( $imageObject );
00335 for ( $y = 0; $y < $height; ++$y )
00336 {
00337 for ( $x = 0; $x < $width; ++$x )
00338 {
00339 $rgb = ImageColorAt( $imageObject, $x, $y );
00340
00341 $r = ( $rgb >> 16 ) & 0xff;
00342 $g = ( $rgb >> 8 ) & 0x0ff;
00343 $b = ( $rgb ) & 0x0ff;
00344
00345 $luminance = ( $r * 0.3 ) + ( $g * 0.59 ) + ( $b * 0.11 );
00346
00347 $r = $luminance * $rmod;
00348 $g = $luminance * $gmod;
00349 $b = $luminance * $bmod;
00350
00351 $color = ImageColorAllocate( $imageObject, $r, $g, $b );
00352
00353 ImageSetPixel( $imageObject, $x, $y, $color );
00354 }
00355 }
00356 return $imageObject;
00357 }
00358
00359
00360
00361
00362
00363 function &setImageColorThresholdName( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00364 {
00365 if ( isset( $this->ThresholdList[$filterData['name']] ) )
00366 {
00367 $thresholdList = $this->ThresholdList[$filterData['name']];
00368 }
00369 else
00370 {
00371 eZDebug::writeDebug( "No threshold values named " . $filterData['name'] . ", applying black/white (monochrome) threshold",
00372 'eZImageGDHandler::setImageLuminanceName' );
00373 $thresholdList = array( array( 'threshold' => 127,
00374 'rgb' => array( 0, 0, 0 ) ),
00375 array( 'threshold' => 255,
00376 'rgb' => array( 255, 255, 255 ) ) );
00377 }
00378 return $this->setImageColorThreshold( $imageObject, $filterData, $sourceMimeData, $destinationMimeData,
00379 $thresholdList );
00380 }
00381
00382
00383
00384
00385
00386 function &setImageColorThreshold( &$imageObject, $filterData, $sourceMimeData, $destinationMimeData,
00387 $thresholdList )
00388 {
00389 foreach ( array_keys( $thresholdList ) as $thresholdKey )
00390 {
00391 $thresholdItem =& $thresholdList[$thresholdKey];
00392 $thresholdItem['color'] = ImageColorAllocate( $imageObject, $thresholdItem['rgb'][0], $thresholdItem['rgb'][1], $thresholdItem['rgb'][2] );
00393 }
00394 $defaultColor = $thresholdList[count( $thresholdList ) - 1]['color'];
00395
00396 $width = ImageSX( $imageObject );
00397 $height = ImageSY( $imageObject );
00398 for ( $y = 0; $y < $height; ++$y )
00399 {
00400 for ( $x = 0; $x < $width; ++$x )
00401 {
00402 $rgb = ImageColorAt( $imageObject, $x, $y );
00403
00404 $r = ( $rgb >> 16 ) & 0xff;
00405 $g = ( $rgb >> 8 ) & 0x0ff;
00406 $b = ( $rgb ) & 0x0ff;
00407
00408 $luminance = ( $r * 0.3 ) + ( $g * 0.59 ) + ( $b * 0.11 );
00409
00410 $color = false;
00411 foreach ( $thresholdList as $thresholdItem )
00412 {
00413 if ( $luminance <= $thresholdItem['threshold'] )
00414 {
00415 $color = $thresholdItem['color'];
00416 break;
00417 }
00418 }
00419 if ( $color === false )
00420 $color = $defaultColor;
00421
00422 ImageSetPixel( $imageObject, $x, $y, $color );
00423 }
00424 }
00425 return $imageObject;
00426 }
00427
00428
00429
00430
00431 function &cropImage( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00432 {
00433 $width = $filterData['data'][0];
00434 $height = $filterData['data'][1];
00435 $x = $filterData['data'][2];
00436 $y = $filterData['data'][3];
00437 $imageWidth = ImageSX( $imageObject );
00438 $imageHeight = ImageSY( $imageObject );
00439 $width = max( min( $width, $imageWidth - $x ), 0 );
00440 $height = max( min( $height, $imageHeight - $y ), 0 );
00441 $destinationGeometry = $this->createGeometry( $width, $height, 0, 0 );
00442 $geometry = $this->createGeometry( $width, $height, $x, $y );
00443 return $this->imageCopy( $imageObject,
00444 $destinationGeometry,
00445 $geometry,
00446 $sourceMimeData, $destinationMimeData );
00447 }
00448
00449
00450
00451
00452
00453
00454 function &scaleImage( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00455 {
00456 $geometry = $this->calculateScaledAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00457 $filterData['data'][0], $filterData['data'][1], true );
00458 return $this->scaleImageCopy( $imageObject,
00459 $geometry,
00460 $sourceMimeData, $destinationMimeData );
00461 }
00462
00463
00464
00465
00466
00467
00468
00469 function &scaleImageDownOnly( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00470 {
00471 $geometry = $this->calculateScaledAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00472 $filterData['data'][0], $filterData['data'][1], false );
00473 $scaleDownOnly =& $this->scaleImageCopy( $imageObject,
00474 $geometry,
00475 $sourceMimeData, $destinationMimeData );
00476
00477 return $scaleDownOnly;
00478 }
00479
00480
00481
00482
00483
00484
00485 function &scaleImageWidth( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00486 {
00487 $geometry = $this->calculateFixedWidthAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00488 $filterData['data'][0], true );
00489 return $this->scaleImageCopy( $imageObject,
00490 $geometry,
00491 $sourceMimeData, $destinationMimeData );
00492 }
00493
00494
00495
00496
00497
00498
00499 function &scaleImageHeight( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00500 {
00501 $geometry = $this->calculateFixedHeightAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00502 $filterData['data'][0], true );
00503 return $this->scaleImageCopy( $imageObject,
00504 $geometry,
00505 $sourceMimeData, $destinationMimeData );
00506 }
00507
00508
00509
00510
00511
00512
00513
00514 function &scaleImageWidthDownOnly( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00515 {
00516 $geometry = $this->calculateFixedWidthAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00517 $filterData['data'][0], false );
00518 return $this->scaleImageCopy( $imageObject,
00519 $geometry,
00520 $sourceMimeData, $destinationMimeData );
00521 }
00522
00523
00524
00525
00526
00527
00528
00529 function &scaleImageHeightDownOnly( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00530 {
00531 $geometry = $this->calculateFixedHeightAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00532 $filterData['data'][0], false );
00533 return $this->scaleImageCopy( $imageObject,
00534 $geometry,
00535 $sourceMimeData, $destinationMimeData );
00536 }
00537
00538
00539
00540
00541 function &scaleImageExact( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00542 {
00543 return $this->scaleImageCopy( $imageObject,
00544 $this->createGeometry( $filterData['data'][0], $filterData['data'][1] ),
00545 $sourceMimeData, $destinationMimeData );
00546 }
00547
00548
00549
00550
00551 function &scaleImagePercent( &$imageObject, $filterData, &$filterVariables, $sourceMimeData, $destinationMimeData )
00552 {
00553 $geometry = $this->calculateScaledPercentAspectGeometry( ImageSX( $imageObject ), ImageSY( $imageObject ),
00554 $filterData['data'][0] / 100.0, $filterData['data'][1] / 100.0, true );
00555 return $this->scaleImageCopy( $imageObject,
00556 $geometry,
00557 $sourceMimeData, $destinationMimeData );
00558 }
00559
00560
00561
00562
00563
00564
00565
00566 function calculateScaledAspectGeometry( $sourceWidth, $sourceHeight,
00567 $destinationWidth, $destinationHeight,
00568 $allowUpScale )
00569 {
00570 $widthScale = $sourceWidth / $destinationWidth;
00571 $heightScale = $sourceHeight / $destinationHeight;
00572
00573 $scale = $heightScale;
00574 if ( $heightScale != $widthScale )
00575 $scale = max( $heightScale, $widthScale );
00576
00577 if ( $scale < 1.0 and !$allowUpScale )
00578 {
00579 $destinationWidth = $sourceWidth;
00580 $destinationHeight = $sourceHeight;
00581 }
00582 else
00583 {
00584 $destinationWidth = (int) ( $sourceWidth / $scale );
00585 $destinationHeight = (int) ( $sourceHeight / $scale );
00586 }
00587 return $this->createGeometry( $destinationWidth, $destinationHeight );
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
00597 function calculateScaledPercentAspectGeometry( $sourceWidth, $sourceHeight,
00598 $destinationWidthPercent, $destinationHeightPercent,
00599 $allowUpScale )
00600 {
00601 $destinationWidth = $sourceWidth * $destinationWidthPercent;
00602 $destinationHeight = $sourceHeight * $destinationHeightPercent;
00603 return $this->calculateScaledAspectGeometry( $sourceWidth, $sourceHeight,
00604 $destinationWidth, $destinationHeight,
00605 $allowUpScale );
00606 }
00607
00608
00609
00610
00611
00612
00613
00614 function calculateFixedWidthAspectGeometry( $sourceWidth, $sourceHeight,
00615 $destinationWidth,
00616 $allowUpScale )
00617 {
00618 $scale = $sourceWidth / $destinationWidth;
00619
00620 if ( $scale < 1.0 and !$allowUpScale )
00621 {
00622 $destinationWidth = $sourceWidth;
00623 $destinationHeight = $sourceHeight;
00624 }
00625 else
00626 {
00627 $destinationWidth = (int) ( $sourceWidth / $scale );
00628 $destinationHeight = (int) ( $sourceHeight / $scale );
00629 }
00630 return $this->createGeometry( $destinationWidth, $destinationHeight );
00631 }
00632
00633
00634
00635
00636
00637
00638
00639 function calculateFixedHeightAspectGeometry( $sourceWidth, $sourceHeight,
00640 $destinationHeight,
00641 $allowUpScale )
00642 {
00643 $scale = $sourceHeight / $destinationHeight;
00644
00645 if ( $scale < 1.0 and !$allowUpScale )
00646 {
00647 $destinationWidth = $sourceWidth;
00648 $destinationHeight = $sourceHeight;
00649 }
00650 else
00651 {
00652 $destinationWidth = (int) ( $sourceWidth / $scale );
00653 $destinationHeight = (int) ( $sourceHeight / $scale );
00654 }
00655 return $this->createGeometry( $destinationWidth, $destinationHeight );
00656 }
00657
00658
00659
00660
00661 function &scaleImageCopy( &$imageObject,
00662 $geometry,
00663 $sourceMimeData, $destinationMimeData )
00664 {
00665 $destinationWidth = $geometry['width'];
00666 $destinationHeight = $geometry['height'];
00667 $sourceWidth = ImageSX( $imageObject );
00668 $sourceHeight = ImageSY( $imageObject );
00669
00670 $temporaryImageObject = $this->imageCreate( $destinationWidth, $destinationHeight, eZImageGDHandler::isImageTrueColor( $imageObject, $sourceMimeData ) );
00671 ImageCopyResampled( $temporaryImageObject, $imageObject,
00672 0, 0, 0, 0,
00673 $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight );
00674 return $temporaryImageObject;
00675 }
00676
00677
00678
00679
00680 function &imageCopy( &$imageObject, $destinationGeometry, $sourceGeometry,
00681 $sourceMimeData, $destinationMimeData )
00682 {
00683 $destinationWidth = $destinationGeometry['width'];
00684 $destinationHeight = $destinationGeometry['height'];
00685
00686 $temporaryImageObject = $this->imageCreate( $destinationWidth, $destinationHeight, eZImageGDHandler::isImageTrueColor( $imageObject, $sourceMimeData ) );
00687 ImageCopy( $temporaryImageObject, $imageObject,
00688 $destinationGeometry['x'], $destinationGeometry['y'],
00689 $sourceGeometry['x'], $sourceGeometry['y'], $sourceGeometry['width'], $sourceGeometry['height'] );
00690 return $temporaryImageObject;
00691 }
00692
00693
00694
00695
00696
00697 function isImageTrueColor( &$imageObject, $mimeData )
00698 {
00699 if ( eZSys::isPHPVersionSufficient( array( 4, 3, 2 ) ) )
00700 return ImageIsTrueColor( $imageObject );
00701 $nonTrueColorMimeTypes = array( 'image/gif' );
00702 if ( in_array( $sourceMimeData['name'], $nonTrueColorMimeTypes ) )
00703 return false;
00704 return true;
00705 }
00706
00707
00708
00709
00710
00711 function imageCreate( $width, $height, $isTrueColor = true )
00712 {
00713 if ( $isTrueColor )
00714 return ImageCreateTrueColor( $width, $height );
00715 else
00716 return ImageCreate( $width, $height );
00717 }
00718
00719
00720
00721
00722 function createGeometry( $width, $height, $x = 0, $y = 0 )
00723 {
00724 return array( 'x' => $x,
00725 'y' => $y,
00726 'width' => $width,
00727 'height' => $height );
00728 }
00729
00730
00731
00732
00733
00734
00735 function &createFromINI( $iniGroup, $iniFilename = false )
00736 {
00737 if ( !$iniFilename )
00738 $iniFilename = 'image.ini';
00739
00740 $handler = false;
00741 include_once( 'lib/ezutils/classes/ezini.php' );
00742 $ini =& eZINI::instance( $iniFilename );
00743 if ( !$ini )
00744 {
00745 eZDebug::writeError( "Failed loading ini file $iniFilename",
00746 'eZImageGDHandler::createFromINI' );
00747 return $handler;
00748 }
00749
00750 if ( $ini->hasGroup( $iniGroup ) )
00751 {
00752 $name = $iniGroup;
00753 if ( $ini->hasVariable( $iniGroup, 'Name' ) )
00754 $name = $ini->variable( $iniGroup, 'Name' );
00755 $conversionRules = false;
00756 if ( $ini->hasVariable( $iniGroup, 'ConversionRules' ) )
00757 {
00758 $conversionRules = array();
00759 $rules = $ini->variable( $iniGroup, 'ConversionRules' );
00760 foreach ( $rules as $ruleString )
00761 {
00762 $ruleItems = explode( ';', $ruleString );
00763 if ( count( $ruleItems ) >= 2 )
00764 {
00765 $conversionRules[] = array( 'from' => $ruleItems[0],
00766 'to' => $ruleItems[1] );
00767 }
00768 }
00769 }
00770 $isEnabled = $ini->variable( $iniGroup, 'IsEnabled' ) == 'true';
00771 $outputRewriteType = EZ_IMAGE_HANDLER_REPLACE_SUFFIX;
00772 $handler = new eZImageGDHandler( $name, $isEnabled,
00773 $outputRewriteType,
00774 $conversionRules );
00775 return $handler;
00776 }
00777 return $handler;
00778 }
00779
00780
00781 var $Path;
00782 var $Executable;
00783 var $PreParameters;
00784 var $PostParameters;
00785 }
00786
00787 class eZImageGDFactory extends eZImageFactory
00788 {
00789
00790
00791
00792 function eZImageGDFactory()
00793 {
00794 $this->eZImageFactory( 'gd' );
00795 }
00796
00797
00798
00799
00800
00801 function &produceFromINI( $iniGroup, $iniFilename = false )
00802 {
00803 $convertHandler =& eZImageGDHandler::createFromINI( $iniGroup, $iniFilename );
00804 return $convertHandler;
00805 }
00806 }
00807
00808 ?>