Changeset 6844
- Timestamp:
- Apr 30, 2008, 2:11:48 AM (15 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
r6843 r6844 236 236 function resize_img($source_gdimg, $w, $h) 237 237 { 238 $s_width = imagesx($source_gdimg); 239 $s_height = imagesy($source_gdimg); 240 241 if (!$w) $w = $s_width; 242 if (!$h) $h = $s_height; 243 244 // リサイズの必要がない場合 245 if ($s_width <= $w && $s_height <= $h) { 246 // 形式変換する場合はGDを通す 247 if ($this->source_format != $this->output_format) { 248 return $source_gdimg; 249 } 250 return false; 251 } 252 253 // 出力サイズ 254 $o_width = $s_width; 255 $o_height = $s_height; 256 257 if ($w < $s_width) { 258 $o_width = $w; 259 $o_height = $s_height * $w / $s_width; 260 } 261 if ($h < $o_height && $h < $s_height) { 262 $o_width = $s_width * $h / $s_height; 263 $o_height = $h; 264 } 265 266 if ($o_height < 1.) { 267 $o_height = 1; 268 } 269 if ($o_width < 1.) { 270 $o_width = 1; 271 } 272 273 $output_gdimg = imagecreatetruecolor($o_width, $o_height); 274 275 if (($this->output_format == 'gif') || ($this->output_format == 'png')) { 276 $trnprt_idx_s = imagecolortransparent($source_gdimg); 277 if ($trnprt_idx_s >= 0) { // 透過色が設定されている 278 imagetruecolortopalette($output_gdimg, true, 256); 279 280 // 入力画像から透明色取得 281 $trnprt_color = imagecolorsforindex($source_gdimg, $trnprt_idx_s); 282 283 // 出力画像に透明色設定 284 imagecolorset($source_gdimg, 0, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); 285 imagefill($output_gdimg, 0, 0, 0); 286 imagecolortransparent($output_gdimg, 0); 287 } elseif ($this->output_format == 'png') { // PNG-24 288 // アルファチャンネル情報を保存するには、アルファブレンディングを解除する必要がある 289 imagealphablending($output_gdimg, false); 290 imagesavealpha($output_gdimg, true); 291 292 // 透過色設定 293 $color = imagecolorallocatealpha($output_gdimg, 0, 0, 0, 127); 294 imagefill($output_gdimg, 0, 0, $color); 295 } 296 } 297 298 imagecopyresampled($output_gdimg, $source_gdimg, 299 0, 0, 0, 0, $o_width, $o_height, $s_width, $s_height); 300 return $output_gdimg; 238 return OpenPNE_Img_Generator::resizeImage($source_gdimg, $w, $h); 301 239 } 302 240 -
OpenPNE/branches/work/ebihara/prj_renew_OpenPNE_Img/webapp/lib/OpenPNE/Img/Generator.php
r6843 r6844 16 16 { 17 17 } 18 19 /** 20 * GDイメージのリサイズ+形式変換 21 * 22 * @param resource $gdimg source GD image 23 * @param int $w width 24 * @param int $h height 25 * @return resource output GD image 26 */ 27 function resizeImage($source_gdimg, $w, $h) 28 { 29 $s_width = imagesx($source_gdimg); 30 $s_height = imagesy($source_gdimg); 31 32 if (!$w) $w = $s_width; 33 if (!$h) $h = $s_height; 34 35 // リサイズの必要がない場合 36 if ($s_width <= $w && $s_height <= $h) { 37 // 形式変換する場合はGDを通す 38 if ($this->source_format != $this->output_format) { 39 return $source_gdimg; 40 } 41 return false; 42 } 43 44 // 出力サイズ 45 $o_width = $s_width; 46 $o_height = $s_height; 47 48 if ($w < $s_width) { 49 $o_width = $w; 50 $o_height = $s_height * $w / $s_width; 51 } 52 if ($h < $o_height && $h < $s_height) { 53 $o_width = $s_width * $h / $s_height; 54 $o_height = $h; 55 } 56 57 if ($o_height < 1.) { 58 $o_height = 1; 59 } 60 if ($o_width < 1.) { 61 $o_width = 1; 62 } 63 64 $output_gdimg = imagecreatetruecolor($o_width, $o_height); 65 66 if (($this->output_format == 'gif') || ($this->output_format == 'png')) { 67 $trnprt_idx_s = imagecolortransparent($source_gdimg); 68 if ($trnprt_idx_s >= 0) { // 透過色が設定されている 69 imagetruecolortopalette($output_gdimg, true, 256); 70 71 // 入力画像から透明色取得 72 $trnprt_color = imagecolorsforindex($source_gdimg, $trnprt_idx_s); 73 74 // 出力画像に透明色設定 75 imagecolorset($source_gdimg, 0, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); 76 imagefill($output_gdimg, 0, 0, 0); 77 imagecolortransparent($output_gdimg, 0); 78 } elseif ($this->output_format == 'png') { // PNG-24 79 // アルファチャンネル情報を保存するには、アルファブレンディングを解除する必要がある 80 imagealphablending($output_gdimg, false); 81 imagesavealpha($output_gdimg, true); 82 83 // 透過色設定 84 $color = imagecolorallocatealpha($output_gdimg, 0, 0, 0, 127); 85 imagefill($output_gdimg, 0, 0, $color); 86 } 87 } 88 89 imagecopyresampled($output_gdimg, $source_gdimg, 90 0, 0, 0, 0, $o_width, $o_height, $s_width, $s_height); 91 return $output_gdimg; 92 } 18 93 } 19 94
Note: See TracChangeset
for help on using the changeset viewer.