| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 define('LIMB_IMAGE_LIBRARY_FLIP_HORIZONTAL', 1); 10 define('LIMB_IMAGE_LIBRARY_FLIP_VERTICAL', 2); 11 12 /** 13 * abstract class lmbImageLibrary. 14 * 15 * @package imagekit 16 * @version $Id: lmbImageLibrary.class.php 5945 2007-06-06 08:31:43Z pachanga $ 17 */ 18 abstract class lmbImageLibrary 19 { 20 var $input_file; 21 var $input_file_type; 22 var $output_file; 23 var $output_file_type; 24 var $read_types = array(); 25 var $create_types = array(); 26 var $library_installed = false; 27 28 function isLibraryInstalled() 29 { 30 return $this->library_installed; 31 } 32 33 function setInputFile($file_path, $file_type=null) 34 { 35 $this->input_file = $file_path; 36 if(!is_null($file_type)) 37 $this->setInputType($file_type); 38 } 39 40 function setInputType($type) 41 { 42 if(!$this->isTypeReadSupported($type)) 43 throw new lmbException("Type '$type' not supported"); 44 45 $this->input_file_type = $type; 46 } 47 48 function setOutputFile($file_path, $file_type=null) 49 { 50 $this->output_file = $file_path; 51 if(!is_null($file_type)) 52 $this->setOutputType($file_type); 53 } 54 55 function setOutputType($type) 56 { 57 if(!$this->isTypeCreateSupported($type)) 58 throw new lmbException("Type '$type' not supported"); 59 60 $this->output_file_type = $type; 61 } 62 63 function fallBackToAnySupportedType($type) 64 { 65 if($this->isTypeCreateSupported($type)) 66 return $type; 67 68 if($this->isTypeCreateSupported('PNG')) 69 return 'PNG'; 70 71 if($this->isTypeCreateSupported('JPEG')) 72 return 'JPEG'; 73 74 throw new lmbException("File type '$type' not supported"); 75 } 76 77 function getImageType($str) 78 { 79 if(preg_match("/bmp/i", $str)) 80 return 'BMP'; 81 82 if(preg_match("/gif/i", $str)) 83 return 'GIF'; 84 85 if(preg_match("/png/i", $str)) 86 return 'PNG'; 87 88 if(preg_match("/(jpeg|jpg)/i", $str)) 89 return 'JPEG'; 90 } 91 92 function getMimeType($str) 93 { 94 if(preg_match("/bmp/i", $str)) 95 return 'image/bmp'; 96 97 if(preg_match("/gif/i", $str)) 98 return 'image/gif'; 99 100 if(preg_match("/png/i", $str)) 101 return 'image/png'; 102 103 if(preg_match("/(jpeg|jpg)/i", $str)) 104 return 'image/jpeg'; 105 } 106 107 function isTypeReadSupported($type) 108 { 109 return in_array(strtoupper($type), $this->read_types); 110 } 111 112 function isTypeCreateSupported($type) 113 { 114 return in_array(strtoupper($type), $this->create_types); 115 } 116 117 function getReadSupportedTypes() 118 { 119 return $this->read_types; 120 } 121 122 function getCreateSupportedTypes() 123 { 124 return $this->create_types; 125 } 126 127 function getDstDimensions($src_width, $src_height, $params) 128 { 129 if(isset($params['max_dimension'])) 130 { 131 $params['preserve_aspect_ratio'] = true; 132 if($src_width > $src_height) 133 $params['width'] = $params['max_dimension']; 134 else 135 $params['height'] = $params['max_dimension']; 136 } 137 138 if(isset($params['scale_factor'])) 139 { 140 $dst_width = floor($src_width * $params['scale_factor']); 141 $dst_height = floor($src_height * $params['scale_factor']); 142 } 143 elseif(isset($params['xscale']) || isset($params['yscale'])) 144 { 145 if(isset($params['xscale'])) 146 $dst_width = floor($src_width * $params['xscale']); 147 else 148 if(isset($params['preserve_aspect_ratio'])) 149 $dst_width = floor($src_width * $params['yscale']); 150 else 151 $dst_width = $src_width; 152 153 if(isset($params['yscale'])) 154 $dst_height = floor($src_height * $params['yscale']); 155 else 156 if(isset($params['preserve_aspect_ratio'])) 157 $dst_height = floor($src_height * $params['xscale']); 158 else 159 $dst_height = $src_height; 160 } 161 elseif(isset($params['width']) || isset($params['height'])) 162 { 163 if(isset($params['width'])) 164 $dst_width = $params['width']; 165 else 166 if(isset($params['preserve_aspect_ratio'])) 167 { 168 $factor = $params['height'] / $src_height; 169 $dst_width = floor($src_width * $factor); 170 } 171 else 172 $dst_width = $src_width; 173 174 if(isset($params['height'])) 175 $dst_height = $params['height']; 176 else 177 if(isset($params['preserve_aspect_ratio'])) 178 { 179 $factor = $params['width'] / $src_width; 180 $dst_height = floor($src_height * $factor); 181 } 182 else 183 $dst_height = $src_height; 184 } 185 186 return array($dst_width, $dst_height); 187 } 188 189 abstract function flip($params); 190 191 abstract function cut($x, $y, $w, $h, $bg_color); 192 193 abstract function resize($params); 194 195 abstract function rotate($angle, $bg_color); 196 197 abstract function commit(); 198 199 function _hexColorToX11($color) 200 { 201 return preg_replace('/(\d{2})(\d{2})(\d{2})/', 'rgb:$1/$2/$3', $color); 202 } 203 } 204 205 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |