Show
Ignore:
Timestamp:
08/01/10 18:38:19 (22 months ago)
Author:
ort
Message:

fix entity and add new method to ModuleImage?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/engine/modules/image/Image.class.php

    r909 r970  
    241241         
    242242        /** 
     243         * Вырезает максимально возможный прямоугольный в нужной пропорции 
     244         * 
     245         * @param LiveImage $oImage 
     246         * @param int $iW 
     247         * @param int $iH 
     248         * @param bool $bCenter 
     249         * @return unknown 
     250         */ 
     251        public function CropProportion(LiveImage $oImage,$iW,$iH,$bCenter=true) { 
     252                 
     253                if(!$oImage || $oImage->get_last_error()) { 
     254                        return false; 
     255                } 
     256                $iWidth  = $oImage->get_image_params('width'); 
     257                $iHeight = $oImage->get_image_params('height'); 
     258                /** 
     259                 * Если высота и ширина уже в нужных пропорциях, то возвращаем изначальный вариант 
     260                 */ 
     261                $iProp=round($iW/$iH, 2); 
     262                if(round($iWidth/$iHeight, 2)==$iProp){ return $oImage; } 
     263                 
     264                /** 
     265                 * Вырезаем прямоугольник из центра 
     266                 */              
     267                if (round($iWidth/$iHeight, 2)<=$iProp) { 
     268                        $iNewWidth=$iWidth; 
     269                        $iNewHeight=round($iNewWidth/$iProp); 
     270                } else {                         
     271                        $iNewHeight=$iHeight; 
     272                        $iNewWidth=$iNewHeight*$iProp; 
     273                } 
     274                 
     275                if ($bCenter) {          
     276                        $oImage->crop($iNewWidth,$iNewHeight,($iWidth-$iNewWidth)/2,($iHeight-$iNewHeight)/2); 
     277                } else {                         
     278                        $oImage->crop($iNewWidth,$iNewHeight,0,0); 
     279                } 
     280                /** 
     281                 * Возвращаем объект изображения 
     282                 */ 
     283                return $oImage; 
     284        } 
     285        /** 
    243286         * Создает каталог по указанному адресу (с учетом иерархии) 
    244287         *