- Timestamp:
- 11/21/11 18:35:22 (6 months ago)
- Location:
- trunk/inc/classes
- Files:
-
- 2 edited
-
BxDolImageResize.php (modified) (5 diffs)
-
BxDolImageTranscoder.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/inc/classes/BxDolImageResize.php
r15512 r15687 35 35 var $_isCrop = false; 36 36 var $_cropX, $_cropY, $_cropW, $_cropH; 37 var $_i sForceJPGOutput = false; ///< force jpeg output37 var $_iForceOutputType = false; ///< force IMAGE_TYPE_PNG, IMAGE_TYPE_PNG, IMAGE_TYPE_GIF or false to keep the original format // TODO: check if this setting works when ImageMagick is used 38 38 var $_iJpegQuality = 75; ///< jpeg quality 39 39 var $_isSquareResize = false; ///< use smart resize, destination image will be exact Width x Height size … … 133 133 } 134 134 135 135 136 function setJpegOutput ($b) { 136 $this->_isForceJPGOutput = ($b ? true : false); 137 $this->setOutputType($b ? IMAGE_TYPE_JPG : false); 138 } 139 140 function setOutputType ($iType) { 141 $this->_iForceOutputType = $iType;; 137 142 } 138 143 … … 184 189 return IMAGE_ERROR_GD_FILTER_ERROR; 185 190 186 // if output always in JPG 187 if ( $this->_isForceJPGOutput ) 188 { 189 $writeResult = imagejpeg( $src_im, $sDstImage, $this->_iJpegQuality); 190 } 191 else // otherwise 192 { 193 switch ( $size[2] ) 194 { 195 case IMAGE_TYPE_GIF: 196 $writeResult = imagegif( $src_im, $sDstImage ); 197 break; 198 case IMAGE_TYPE_JPG: 199 $writeResult = imagejpeg( $src_im, $sDstImage, $this->_iJpegQuality); 200 break; 201 case IMAGE_TYPE_PNG: 202 $writeResult = imagepng( $src_im, $sDstImage ); 203 break; 204 } 205 } 191 $writeResult = $this->_writeImageGD ($src_im, $sDstImage); 206 192 207 193 // free memory … … 347 333 return IMAGE_ERROR_GD_RESIZE_ERROR; 348 334 349 // if output always in JPG 350 if ( $this->_isForceJPGOutput ) 351 { 352 $writeResult = imagejpeg( $dst_im, $sDstImage, $this->_iJpegQuality); 353 } 354 else // otherwise 355 { 356 switch ( $size[2] ) 357 { 358 case IMAGE_TYPE_GIF: 359 $writeResult = imagegif( $dst_im, $sDstImage ); 360 break; 361 case IMAGE_TYPE_JPG: 362 $writeResult = imagejpeg( $dst_im, $sDstImage, $this->_iJpegQuality); 363 break; 364 case IMAGE_TYPE_PNG: 365 $writeResult = imagepng( $dst_im, $sDstImage ); 366 break; 367 } 368 } 335 $writeResult = $this->_writeImageGD ($dst_im, $sDstImage); 369 336 370 337 // free memory … … 545 512 } 546 513 } 514 515 function _writeImageGD ($src_im, $sDstImage) { 516 517 $writeResult = false; 518 519 switch ($this->_iForceOutputType){ 520 521 case IMAGE_TYPE_JPG: 522 $writeResult = imagejpeg( $src_im, $sDstImage, $this->_iJpegQuality); 523 break; 524 525 case IMAGE_TYPE_PNG: 526 $writeResult = imagepng( $src_im, $sDstImage); 527 break; 528 529 case IMAGE_TYPE_GIF: 530 $writeResult = imagegif( $src_im, $sDstImage ); 531 break; 532 533 default: 534 switch ( $size[2] ) { 535 case IMAGE_TYPE_GIF: 536 $writeResult = imagegif( $src_im, $sDstImage ); 537 break; 538 case IMAGE_TYPE_PNG: 539 $writeResult = imagepng( $src_im, $sDstImage ); 540 break; 541 case IMAGE_TYPE_JPG: 542 default: 543 $writeResult = imagejpeg( $src_im, $sDstImage, $this->_iJpegQuality); 544 break; 545 } 546 } 547 548 return $writeResult; 549 } 547 550 } 548 551 -
trunk/inc/classes/BxDolImageTranscoder.php
r15663 r15687 62 62 * - h - height of resulted image. 63 63 * - square_resize - make resulted image square, even of original image is not square, 'w' and 'h' parameters must be the same. 64 * - force_ jpeg - always change type of the image to jpeg.64 * - force_type - always change type of the image to the specified type: jpg, png, gif. 65 65 * - Grayscale - make image grayscale, there is no parameters for this filter 66 66 * … … 267 267 */ 268 268 public function transcode ($mixedHandler, $iProfileId = 0) { 269 270 $sExtChange = false; 269 271 270 272 // create tmp file locally … … 284 286 return false; 285 287 } 288 289 if (!empty($aParams['filter_params']['force_type'])) { 290 switch ($aParams['filter_params']['force_type']) { 291 case 'jpeg': 292 case 'jpg': 293 $sExtChange = 'jpg'; 294 break; 295 case 'png': 296 $sExtChange = 'png'; 297 break; 298 case 'gif': 299 $sExtChange = 'gif'; 300 break; 301 } 302 } 303 } 304 305 if ($sExtChange && false !== ($iDotPos = strrpos($sTmpFile, '.'))) { 306 $sExtOld = substr($sTmpFile, $iDotPos+1); 307 if ($sExtOld != $sExtChange) { 308 $sTmpFileOld = $sTmpFile; 309 $sTmpFile = substr_replace ($sTmpFile, $sExtChange, $iDotPos+1, strlen($sExtOld)); 310 if (!rename($sTmpFileOld, $sTmpFile)) { 311 unlink($sTmpFileOld); 312 return false; 313 } 314 } 315 286 316 } 287 317 … … 453 483 $o->removeCropOptions (); 454 484 485 $this->_checkForceType ($o, $aParams); 486 455 487 if (IMAGE_ERROR_SUCCESS == $o->grayscale($sFile)) 456 488 return true; … … 465 497 466 498 if (isset($aParams['w']) && isset($aParams['h'])) 467 $o->setSize ($aParams['w'], $aParams['h']); 468 469 if (isset($aParams['force_jpeg']) && $aParams['force_jpeg']) 470 $o->setJpegOutput (true); 471 else 472 $o->setJpegOutput (false); 499 $o->setSize ($aParams['w'], $aParams['h']); 473 500 474 501 if (isset($aParams['square_resize']) && $aParams['square_resize']) … … 477 504 $o->setSquareResize (false); 478 505 506 $this->_checkForceType ($o, $aParams); 507 479 508 if (IMAGE_ERROR_SUCCESS == $o->resize($sFile)) 480 509 return true; 481 510 482 511 return false; 512 } 513 514 protected function _checkForceType ($oImageProcessor, $aParams) { 515 if (empty($aParams['force_type'])) 516 $aParams['force_type'] = false; 517 518 switch ($aParams['force_type']) { 519 case 'jpeg': 520 case 'jpg': 521 $oImageProcessor->setOutputType(IMAGE_TYPE_JPG); 522 break; 523 case 'png': 524 $oImageProcessor->setOutputType(IMAGE_TYPE_PNG); 525 break; 526 case 'gif': 527 $oImageProcessor->setOutputType(IMAGE_TYPE_GIF); 528 break; 529 default: 530 $oImageProcessor->setOutputType(false); 531 break; 532 } 483 533 } 484 534
Note: See TracChangeset
for help on using the changeset viewer.