| [ Index ] |
PHP Cross Reference of Akelos Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4 // +----------------------------------------------------------------------+ 5 // | Akelos Framework - http://www.akelos.org | 6 // +----------------------------------------------------------------------+ 7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez | 8 // | Released under the GNU Lesser General Public License, see LICENSE.txt| 9 // +----------------------------------------------------------------------+ 10 11 /** 12 * @package ActiveSupport 13 * @subpackage ImageManipulation 14 * @author Bermi Ferrer <bermi a.t akelos c.om> 15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org 16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 17 */ 18 19 /** 20 * Resizing filter 21 * 22 * Options are: 23 * 'width 24 * 'height' 25 * 'mode' This setting will define how the image will be resized. Options are: 26 * - "normal" (default) will shrink to the largest side but will not grow the image if it is smaller 27 * - "expand" grows the image to the largest side 28 * - "force" forces the image to an specific size without maintaining the aspect ratio 29 */ 30 class AkImageResizeFilter extends AkImageFilter 31 { 32 // Image->path 33 // Image->filter_backup->path 34 function setOptions($options = array()) 35 { 36 $default_options = array( 37 'width'=> $this->Image->getWidth(), 38 'height'=> $this->Image->getHeight(), 39 'scale_method' => 'smooth', 40 'mode' => 'normal' 41 ); 42 43 $this->_setWidthAndHeight_($options); 44 $this->options = array_merge($default_options, $options); 45 $this->_recalculateTargetDimenssions(); 46 $this->_variablizeOptions_($options); 47 } 48 49 function apply() 50 { 51 $this->Image->Transform->resize($this->options['width'], $this->options['height'], $this->options); 52 } 53 54 function getName() 55 { 56 return 'resize'; 57 } 58 59 function _setWidthAndHeight_(&$options) 60 { 61 if(!empty($options['size'])){ 62 list($options['width'], $options['height']) = split('x|X| ',trim(str_replace(' ','',$options['size'])).'x'); 63 unset($options['size']); 64 } 65 66 if(strstr($options['width'],'%')){ 67 $options['width'] = $this->_getProportionalWidth($options['width']); 68 } 69 if(strstr($options['height'],'%')){ 70 $options['height'] = $this->_getProportionalHeight($options['height']); 71 } 72 } 73 74 function _recalculateTargetDimenssions() 75 { 76 $original_width = $this->Image->getWidth(); 77 $original_height = $this->Image->getHeight(); 78 79 $target_width = empty($this->options['width']) ? $original_width : $this->options['width']; 80 $target_height = empty($this->options['height']) ? $original_height : $this->options['height']; 81 82 if($this->options['mode'] == 'normal' && $original_width < $target_width && $original_height < $target_height) { 83 84 $this->options['width'] = $original_width; 85 $this->options['height'] = $original_height; 86 return true; 87 } 88 89 if ($this->options['mode'] != 'force') { 90 91 $original_aspect_ratio = $original_height / $original_width; 92 $target_aspect_ratio = $target_height / $target_width; 93 94 if ($this->options['mode'] != 'expand') { 95 if ($original_aspect_ratio > $target_aspect_ratio) { 96 $target_width = $original_width / $original_height * $target_height; 97 } else { 98 $target_height = $original_height / $original_width * $target_width; 99 } 100 } else { 101 if ($original_aspect_ratio > $target_aspect_ratio) { 102 $target_height = $original_height / $original_width * $target_width; 103 } else { 104 $target_width = $original_width / $original_height * $target_height; 105 } 106 } 107 } 108 109 $this->options['width'] = $target_width; 110 $this->options['height'] = $target_height; 111 } 112 113 function _getProportionalWidth($proportion = '100%') 114 { 115 return intval($proportion)/100*$this->Image->getWidth(); 116 } 117 118 function _getProportionalHeight($proportion = '100%') 119 { 120 return intval($proportion)/100*$this->Image->getHeight(); 121 } 122 } 123 124 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Oct 27 12:43:49 2008 | Cross-referenced by PHPXref 0.6 |