| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 4 | * |
|---|
| 5 | * http://www.lockon.co.jp/ |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | //---- ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë²Ã¹©¥¯¥é¥¹(thumb.php¤È¥»¥Ã¥È¤Ç»ÈÍѤ¹¤ë) |
|---|
| 9 | class SC_Image { |
|---|
| 10 | |
|---|
| 11 | var $tmp_dir; |
|---|
| 12 | |
|---|
| 13 | function SC_Image($tmp_dir) { |
|---|
| 14 | // ¥Ø¥Ã¥À¥Õ¥¡¥¤¥ëÆÉ¹þ |
|---|
| 15 | $include_dir = realpath(dirname( __FILE__)); |
|---|
| 16 | require_once($include_dir . "/../lib/thumb.php"); |
|---|
| 17 | if(!ereg("/$", $tmp_dir)) { |
|---|
| 18 | $this->tmp_dir = $tmp_dir . "/"; |
|---|
| 19 | } else { |
|---|
| 20 | $this->tmp_dir = $tmp_dir; |
|---|
| 21 | } |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | //--- °ì»þ¥Õ¥¡¥¤¥ëÀ¸À®(¥µ¥à¥Í¥¤¥ë²èÁüÀ¸À®ÍÑ) |
|---|
| 25 | function makeTempImage($keyname, $max_width, $max_height) { |
|---|
| 26 | // °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£ |
|---|
| 27 | $mainname = uniqid("")."."; |
|---|
| 28 | // ³ÈÄ¥»Ò°Ê³°¤òÃÖ¤´¹¤¨¤ë¡£ |
|---|
| 29 | $newFileName = ereg_replace("^.*\.",$mainname, $_FILES[$keyname]['name']); |
|---|
| 30 | $result = MakeThumb($_FILES[$keyname]['tmp_name'], $this->tmp_dir , $max_width, $max_height, $newFileName); |
|---|
| 31 | gfDebugLog($result); |
|---|
| 32 | return $newFileName; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | //--- ¥Õ¥¡¥¤¥ë¤ò»ØÄêÊݸDIR¤Ø°Üư |
|---|
| 36 | function moveTempImage($filename, $save_dir) { |
|---|
| 37 | // ¥³¥Ô¡¼¸µ¥Õ¥¡¥¤¥ë¡¢¥³¥Ô¡¼Àè¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤¹¤ë¾ì¹ç¤Ë¤Î¤ß¼Â¹Ô¤¹¤ë |
|---|
| 38 | if(file_exists($this->tmp_dir.$filename) && file_exists($save_dir)) { |
|---|
| 39 | if(copy($this->tmp_dir . $filename , $save_dir."/".$filename)) { |
|---|
| 40 | unlink( $this->tmp_dir . $filename ); |
|---|
| 41 | } |
|---|
| 42 | } else { |
|---|
| 43 | gfDebugLog($this->tmp_dir.$filename."¤Î°Üư¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£"); |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | //---- »ØÄê¥Õ¥¡¥¤¥ë¤òºï½ü |
|---|
| 48 | function deleteImage($filename, $dir) { |
|---|
| 49 | if(file_exists($dir."/".$filename)) { |
|---|
| 50 | unlink($dir."/".$filename); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 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 | } |
|---|
| 163 | ?> |
|---|