Changeset 9284 for temp/trunk/data/class
- Timestamp:
- 2006/11/28 11:08:49 (20 years ago)
- File:
-
- 1 edited
-
temp/trunk/data/class/SC_Image.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
temp/trunk/data/class/SC_Image.php
r9283 r9284 52 52 } 53 53 54 // ³ÈÂçΨ¤ò»ØÄꤷ¤Æ²èÁüÊݸ55 function saveResizeImage($file, $to_w = 0, $to_h = 0, $header = false) {56 // ¥Ç¥£¥ì¥¯¥È¥ê¼èÆÀ57 $dir = dirname($file);58 59 // ¸µ²èÁü¥µ¥¤¥º¤ò¼èÆÀ60 list($from_w, $from_h) = getimagesize($file);61 62 if($to_w > 0 or $to_h > 0){63 // Éý¤Î½Ì¾®Î¨64 ($to_w < $from_w) ? $wscale = $to_w / $from_w : $wscale = 1;65 // ¹â¤µ¤Î½Ì¾®Î¨66 ($to_h < $from_h) ? $hscale = $to_h / $from_h : $hscale = 1;67 // ½Ì¾®Î¨¤Ï¾®¤µ¤¤¤Û¤¦¤Ë¤¢¤ï¤»¤ë68 ($wscale < $hscale) ? $scale = $wscale : $scale = $hscale;69 }else{70 $scale = 1;71 }72 73 // °µ½ÌΨ»ØÄê74 $zip_width = $from_w * $scale;75 $zip_height = $from_h * $scale;76 77 // ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¼èÆÀ78 $arrFileInfo = pathinfo($file);79 $extension = $arrFileInfo["extension"];80 81 // °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£82 $uniqname = date("mdHi") . "_" . uniqid("");83 84 // ¥Õ¥¡¥¤¥ë̾¡¢ÊݸÀèÀßÄê85 $filename = $uniqname . "." . $extension;86 $path = $dir . "/" . $filename;87 88 // ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¤Ë¤è¤Ã¤Æ½èÍý¤òʬ¤±¤ë89 if(is_dir($dir)) {90 switch ($extension) {91 case "jpg":92 case "jpeg":93 //¸µ²èÁü94 $src_im = ImageCreateFromJPEG($file);95 96 // °µ½ÌÀè²èÁü97 $dst_im = imagecreatetruecolor($zip_width, $zip_height);98 imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $zip_width, $zip_height, $from_w, $from_h);99 100 // ²èÁü½ÐÎÏ101 if($header){102 header("Content-Type: image/jpeg");103 ImageJPEG($dst_im);104 }else{105 ImageJPEG($dst_im, $path);106 }107 108 break;109 case "gif":110 //¸µ²èÁü111 $src_im = ImageCreateFromGIF($file);112 113 // °µ½ÌÀè²èÁü114 //$dst_im = imagecreatetruecolor($zip_width, $zip_height);115 $dst_im = ImageCreate($zip_width, $zip_height);116 //imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $from_w, $from_h);117 imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $zip_width, $zip_height, $from_w, $from_h);118 119 // ²èÁü½ÐÎÏ120 if($header){121 header("Content-Type: image/gif");122 ImageGIF($dst_im);123 }else{124 ImageGIF($dst_im, $path);125 }126 break;127 case "png":128 //¸µ²èÁü129 $src_im = ImageCreateFromPNG($file);130 131 // °µ½ÌÀè²èÁü132 $dst_im = imagecreatetruecolor($zip_width, $zip_height);133 imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $from_w, $from_h);134 135 // ²èÁü½ÐÎÏ136 if($header){137 header("Content-Type: image/png");138 ImagePNG($dst_im);139 }else{140 ImagePNG($dst_im, $path);141 }142 143 break;144 default:145 print("³ÈÄ¥»Ò¤¬ÉÔÀµ¤Ç¤¹¡£");146 $path = "";147 break;148 }149 ImageDestroy($src_im);150 ImageDestroy($dst_im);151 152 if(!$header){153 return $path;154 }else{155 return "";156 }157 }158 159 print("²èÁü¤ÎÊݸ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");160 return "";161 }162 54 } 163 55 ?>
Note: See TracChangeset
for help on using the changeset viewer.
