Changeset 6911
- Timestamp:
- May 2, 2008, 3:43:07 AM (14 years ago)
- Location:
- OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/OpenPNE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/OpenPNE/Img.php
r6909 r6911 14 14 var $height = 0; 15 15 var $filename = ''; 16 17 /**18 * 変換を許可する画像サイズ19 *20 * この配列にあるサイズの画像のみ出力できる。21 * 空の場合は無制限となる。22 *23 * @var array24 */25 var $allowed_size;26 16 27 17 /** … … 43 33 function OpenPNE_Img($options = array()) 44 34 { 45 $this->allowed_size = (array)$GLOBALS['_OPENPNE_IMG_ALLOWED_SIZE'];46 if (isset($options['allowed_size'])) {47 $this->allowed_size = $options['allowed_size'];48 }49 50 35 $this->generator = new OpenPNE_Img_Generator($options); 51 36 $this->storage = new OpenPNE_Img_Storage($options); … … 68 53 $height = $vars['h']; 69 54 } 70 $this-> setSize($width, $height);55 $this->generator->setImageSize($width, $height); 71 56 72 57 if (!empty($vars['f'])) { … … 76 61 if (!empty($vars['filename'])) { 77 62 $this->setFilename($vars['filename']); 78 }79 }80 81 /**82 * ファイルの高さ・幅をセット83 *84 * @param int $width85 * @param int $height86 */87 function setSize($width = 0, $height = 0)88 {89 if (is_numeric($width)) {90 $this->width = intval($width);91 }92 93 if (is_numeric($height)) {94 $this->height = intval($height);95 63 } 96 64 } … … 119 87 } 120 88 121 if (!$this->isAllowedSize($this->width, $this->height)) { 122 return false; 123 } 124 125 $this->generator->setCacheFilename($this->filename, $this->width, $this->height); 89 $this->generator->setCacheFilename($this->filename); 126 90 if ($this->generator->isCacheReadable()) { 127 91 return true; 128 92 } 93 129 94 if (!$raw_img = $this->storage->getRawImage($this->filename)) { 130 95 return false; 131 96 } 132 97 133 return $this->generator->createImage($raw_img, $this-> width, $this->height, $this->format);98 return $this->generator->createImage($raw_img, $this->format); 134 99 } 135 100 … … 177 142 } 178 143 179 /**180 * 変換可能な画像サイズかどうか181 *182 * @param int $width183 * @param int $height184 * @return bool185 */186 function isAllowedSize($width = 0, $height = 0)187 {188 if (!$width && !$height) {189 return true;190 }191 192 $size = sprintf('%dx%d', $width, $height);193 if ($this->allowed_size && !in_array($size, $this->allowed_size)) {194 return false;195 }196 197 return true;198 }199 144 } 200 145 -
OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/OpenPNE/Img/Generator.php
r6910 r6911 14 14 { 15 15 var $jpeg_quality = 75; 16 var $width = 0; 17 var $height = 0; 16 18 17 19 var $source_format; … … 21 23 var $cache_fullpath; 22 24 25 /** 26 * 変換を許可する画像サイズ 27 * 28 * この配列にあるサイズの画像のみ出力できる。 29 * 空の場合は無制限となる。 30 * 31 * @var array 32 */ 33 var $allowed_size; 34 23 35 function OpenPNE_Img_Generator($options = array()) 24 36 { 37 $this->allowed_size = (array)$GLOBALS['_OPENPNE_IMG_ALLOWED_SIZE']; 38 if (isset($options['allowed_size'])) { 39 $this->allowed_size = $options['allowed_size']; 40 } 41 25 42 if (!empty($options['jpeg_quality'])) { 26 43 $this->jpeg_quality = $options['jpeg_quality']; … … 32 49 } 33 50 34 function createImage($raw_img, $w, $h, $format) 35 { 51 function createImage($raw_img, $format) 52 { 53 $w = $this->width; 54 $h = $this->height; 55 56 if (!$this->isAllowedSize($w, $h)) { 57 return false; 58 } 59 36 60 // サイズ指定がなく、かつ、形式変換しない場合(GDに変換する必要なし) 37 61 if (!$w && !$h && ($this->getSourceFormat() == $this->getOutputFormat())) { … … 204 228 } 205 229 206 function setCacheFileName($filename , $w, $h)230 function setCacheFileName($filename) 207 231 { 208 232 $pieces = explode('.', $filename); … … 213 237 $this->cache_fullpath = 214 238 $this->cache_dir . '/' . 215 $this->getCachePath($filename, $ w, $h, $f);239 $this->getCachePath($filename, $this->width, $this->height, $f); 216 240 } 217 241 … … 225 249 } 226 250 251 /** 252 * ファイルの高さ・幅をセット 253 * 254 * @param int $width 255 * @param int $height 256 */ 257 function setImageSize($width = 0, $height = 0) 258 { 259 if (is_numeric($width)) { 260 $this->width = $width; 261 } 262 263 if (is_numeric($height)) { 264 $this->height = $height; 265 } 266 } 267 227 268 function setSourceFormat($source_format) 228 269 { … … 261 302 return is_readable($this->cache_fullpath); 262 303 } 304 305 /** 306 * 変換可能な画像サイズかどうか 307 * 308 * @param int $width 309 * @param int $height 310 * @return bool 311 */ 312 function isAllowedSize($width = 0, $height = 0) 313 { 314 if (!$width && !$height) { 315 return true; 316 } 317 318 $size = sprintf('%dx%d', $width, $height); 319 if ($this->allowed_size && !in_array($size, $this->allowed_size)) { 320 return false; 321 } 322 323 return true; 324 } 263 325 } 264 326
Note: See TracChangeset
for help on using the changeset viewer.