HomeHelpTrac

Changeset 15687 for trunk/inc


Ignore:
Timestamp:
11/21/11 18:35:22 (6 months ago)
Author:
Alexander Trofimov
Message:

Images Transcoder - 'force_jpeg' parameter was changed to 'force_type'

Location:
trunk/inc/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/inc/classes/BxDolImageResize.php

    r15512 r15687  
    3535    var $_isCrop = false; 
    3636    var $_cropX, $_cropY, $_cropW, $_cropH; 
    37     var $_isForceJPGOutput = false; ///< force  jpeg output 
     37    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 
    3838    var $_iJpegQuality = 75; ///< jpeg quality 
    3939    var $_isSquareResize = false; ///< use smart resize, destination image will be exact Width x Height size 
     
    133133    } 
    134134 
     135 
    135136    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;; 
    137142    } 
    138143 
     
    184189            return IMAGE_ERROR_GD_FILTER_ERROR; 
    185190 
    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); 
    206192 
    207193        // free memory 
     
    347333            return IMAGE_ERROR_GD_RESIZE_ERROR; 
    348334 
    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); 
    369336 
    370337        // free memory 
     
    545512        } 
    546513    } 
     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    } 
    547550} 
    548551 
  • trunk/inc/classes/BxDolImageTranscoder.php

    r15663 r15687  
    6262 *     - h - height of resulted image. 
    6363 *     - 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. 
    6565 * - Grayscale - make image grayscale, there is no parameters for this filter 
    6666 * 
     
    267267     */ 
    268268    public function transcode ($mixedHandler, $iProfileId = 0) { 
     269 
     270        $sExtChange = false; 
    269271 
    270272        // create tmp file locally  
     
    284286                return false; 
    285287            } 
     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 
    286316        } 
    287317 
     
    453483        $o->removeCropOptions (); 
    454484 
     485        $this->_checkForceType ($o, $aParams); 
     486 
    455487        if (IMAGE_ERROR_SUCCESS == $o->grayscale($sFile)) 
    456488            return true; 
     
    465497 
    466498        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']);                 
    473500 
    474501        if (isset($aParams['square_resize']) && $aParams['square_resize']) 
     
    477504            $o->setSquareResize (false); 
    478505 
     506        $this->_checkForceType ($o, $aParams); 
     507 
    479508        if (IMAGE_ERROR_SUCCESS == $o->resize($sFile)) 
    480509            return true; 
    481510 
    482511        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        } 
    483533    } 
    484534 
Note: See TracChangeset for help on using the changeset viewer.