| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | |
|---|
| 4 | ¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡ |
|---|
| 5 | GD¼«Æ°¥µ¥à¥Í¥¤¥ëºîÀ® + ÃæÀÀµ2006/02/03 |
|---|
| 6 | |
|---|
| 7 | Copyright 2002- Akihiro Asai. All rights reserved. |
|---|
| 8 | |
|---|
| 9 | http://aki.adam.ne.jp |
|---|
| 10 | [email protected] |
|---|
| 11 | |
|---|
| 12 | ¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡¢¡ |
|---|
| 13 | |
|---|
| 14 | ¢¢ µ¡Ç½³µÍ× |
|---|
| 15 | ¡¦»ØÄꤵ¤ì¤¿¥¤¥á¡¼¥¸¤Î¥µ¥à¥Í¥¤¥ë¤òɽ¼¨¤·¤Þ¤¹¡£ |
|---|
| 16 | ¡¦½ÐÎϤ¹¤ëÂ礤µ¤ò»ØÄꤹ¤ë»ö¤¬¤Ç¤¤Þ¤¹¡£ |
|---|
| 17 | ¡¦½ÐÎϤµ¤ì¤ë¥¤¥á¡¼¥¸¤Î¥¢¥¹¥Ú¥¯¥ÈÈæ¤Ï°Ý»ý¤µ¤ì¤Þ¤¹¡£ |
|---|
| 18 | |
|---|
| 19 | ¢¢ »ÈÍÑÊýË¡ |
|---|
| 20 | »ØÄê¤Ï gdthumb.php?path=xxx/xxx.[ jpg | png | gif ]&mw=xx&mh=xx |
|---|
| 21 | ¢¨ pass¤ÎÉôʬ¤Ë¤Ï²èÁü¤Ø¤Î¥Ñ¥¹¤ò»ØÄê |
|---|
| 22 | ¢¨ mw¤Ëɽ¼¨²èÁü¤ÎºÇÂç²£Éý¡¢mh¤Ëɽ¼¨²èÁü¤ÎºÇÂç²£Éý¤ò³°Éô¤è¤ê»ØÄê²Äǽ¡£ |
|---|
| 23 | ¢¨ »ØÄꤷ¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¥Ç¥Õ¥©¥ë¥È¤ÎÀßÄêÃͤòºÎÍÑ¡£ |
|---|
| 24 | ¡ú¥¯¥é¥¹¤È¤·¤Æ»ÈÍѤ¹¤ë¾ì¹ç¤Ï¡¢¡Ö¥¯¥é¥¹¤È¤·¤Æ»ÈÍѤ¹¤ë¾ì¹ç¤Ë¤Ï¡¦¡¦¡¦¡×°Ê¹ß¤ò¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ²¼¤µ¤¤¡£ |
|---|
| 25 | |
|---|
| 26 | ¢¢ ¹¹¿·ÍúÎò |
|---|
| 27 | 2002/08/19 ºÇÂç½ÄÉý¤ÎÉôʬ¤ò°ìÉô¼êľ¤· |
|---|
| 28 | 2003/01/31 ¥Ç¥Õ¥©¥ë¥È¤Ç¥¢¥¹¥Ú¥¯¥ÈÈæ¤¬¸ÇÄê |
|---|
| 29 | 2003/04/11 ºÇÂç²£Éý¤ÈºÇÂç½ÄÉý¤ò³°Éô¤è¤ê»ØÄê²Äǽ |
|---|
| 30 | 2003/04/25 GD2ÍѤ˴ؿôÊѹ¹ |
|---|
| 31 | 2003/06/21 GD1/2¤ò¥Ð¡¼¥¸¥ç¥ó¤Ë±þ¤¸¤ÆÊѹ¹¤Ç¤¤ë¤è¤¦¤Ë½¤Àµ |
|---|
| 32 | 2003/06/25 imageCopyResampled¤ÎÉôʬ¤ò½¤Àµ |
|---|
| 33 | 2004/01/28 ¥¹¥¯¥ê¥×¥ÈÁ´ÂΤò½ñ¤Ä¾¤·¡£°ú¿ô¡Öpass¡×¤ò¡Öpath¡×¤ËÊѹ¹¡£ |
|---|
| 34 | 2005/12/08 ´Ø¿ô¤Î¼«Æ°È½ÊÌ gif·Á¼°¤ËÂбþ Æ©²ágif¡¦Æ©²ápng¤ËÂбþ¡ÊGD2.0.1°Ê¹ß¡Ë |
|---|
| 35 | */ |
|---|
| 36 | |
|---|
| 37 | // ¥¯¥é¥¹¤È¤·¤Æ»ÈÍѤ¹¤ë¾ì¹ç¤Ë¤Ï¡¢°Ê²¼¤Î6¹Ô¤ò¥³¥á¥ó¥È¥¢¥¦¥È |
|---|
| 38 | /* |
|---|
| 39 | $objg = new gdthumb(); |
|---|
| 40 | list($Ck, $Msg) = $objg->Main($_GET["path"], $_GET["mw"], $_GET["mh"]); |
|---|
| 41 | if(!$Ck) { // ¥¨¥é¡¼¤Î¾ì¹ç |
|---|
| 42 | header("Content-Type: text/html; charset=" . CHAR_CODE); |
|---|
| 43 | print $Msg; |
|---|
| 44 | } |
|---|
| 45 | */ |
|---|
| 46 | |
|---|
| 47 | class gdthumb { |
|---|
| 48 | |
|---|
| 49 | var $imgMaxWidth; |
|---|
| 50 | var $imgMaxHeight; |
|---|
| 51 | var $gdVer; |
|---|
| 52 | |
|---|
| 53 | /* |
|---|
| 54 | * ¥³¥ó¥¹¥È¥é¥¯¥¿ |
|---|
| 55 | */ |
|---|
| 56 | function gdthumb() { |
|---|
| 57 | |
|---|
| 58 | // ¥¹¥¯¥ê¥×¥È¤Î¥Ç¥Õ¥©¥ë¥ÈÀßÄê |
|---|
| 59 | |
|---|
| 60 | // ²èÁü¤ÎºÇÂç²£Éý |
|---|
| 61 | $this->imgMaxWidth = 240; // 1°Ê¾å¤ÎÃÍ |
|---|
| 62 | |
|---|
| 63 | // ²èÁü¤ÎºÇÂç½ÄÉý |
|---|
| 64 | $this->imgMaxHeight = 0; // »ØÄꤷ¤Ê¤¤¾ì¹ç¤Ï0 »ØÄꤹ¤ë¾ì¹ç¤Ï1°Ê¾å¤ÎÃÍ |
|---|
| 65 | |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /* |
|---|
| 69 | * ¥µ¥à¥Í¥¤¥ë²èÁü¤ÎºîÀ® |
|---|
| 70 | * string $path |
|---|
| 71 | * integer $width |
|---|
| 72 | * integer $height |
|---|
| 73 | */ |
|---|
| 74 | function Main($path, $width, $height, $dst_file, $header = false) { |
|---|
| 75 | |
|---|
| 76 | if(!isset($path)) { |
|---|
| 77 | return array(0, "¥¤¥á¡¼¥¸¤Î¥Ñ¥¹¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£"); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | if(!file_exists($path)) { |
|---|
| 81 | return array(0, "»ØÄꤵ¤ì¤¿¥Ñ¥¹¤Ë¥Õ¥¡¥¤¥ë¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó¡£"); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | // ²èÁü¤ÎÂ礤µ¤ò¥»¥Ã¥È |
|---|
| 85 | if($width) $this->imgMaxWidth = $width; |
|---|
| 86 | if($height) $this->imgMaxHeight = $height; |
|---|
| 87 | |
|---|
| 88 | $size = @GetimageSize($path); |
|---|
| 89 | $re_size = $size; |
|---|
| 90 | |
|---|
| 91 | //¥¢¥¹¥Ú¥¯¥ÈÈæ¸ÇÄê½èÍý |
|---|
| 92 | if($this->imgMaxWidth != 0) { |
|---|
| 93 | $tmp_w = $size[0] / $this->imgMaxWidth; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | if($this->imgMaxHeight != 0) { |
|---|
| 97 | $tmp_h = $size[1] / $this->imgMaxHeight; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | if($tmp_w > 1 || $tmp_h > 1) { |
|---|
| 101 | if($this->imgMaxHeight == 0) { |
|---|
| 102 | if($tmp_w > 1) { |
|---|
| 103 | $re_size[0] = $this->imgMaxWidth; |
|---|
| 104 | $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0]; |
|---|
| 105 | } |
|---|
| 106 | } else { |
|---|
| 107 | if($tmp_w > $tmp_h) { |
|---|
| 108 | $re_size[0] = $this->imgMaxWidth; |
|---|
| 109 | $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0]; |
|---|
| 110 | } else { |
|---|
| 111 | $re_size[1] = $this->imgMaxHeight; |
|---|
| 112 | $re_size[0] = $size[0] * $this->imgMaxHeight / $size[1]; |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | $imagecreate = function_exists("imagecreatetruecolor") ? "imagecreatetruecolor" : "imagecreate"; |
|---|
| 118 | $imageresize = function_exists("imagecopyresampled") ? "imagecopyresampled" : "imagecopyresized"; |
|---|
| 119 | |
|---|
| 120 | switch($size[2]) { |
|---|
| 121 | |
|---|
| 122 | // gif·Á¼° |
|---|
| 123 | case "1": |
|---|
| 124 | if(function_exists("imagecreatefromgif")) { |
|---|
| 125 | $src_im = imagecreatefromgif($path); |
|---|
| 126 | $dst_im = $imagecreate($re_size[0], $re_size[1]); |
|---|
| 127 | |
|---|
| 128 | $transparent = imagecolortransparent($src_im); |
|---|
| 129 | $colorstotal = imagecolorstotal ($src_im); |
|---|
| 130 | |
|---|
| 131 | $dst_im = imagecreate($re_size[0], $re_size[1]); |
|---|
| 132 | if (0 <= $transparent && $transparent < $colorstotal) { |
|---|
| 133 | imagepalettecopy ($dst_im, $src_im); |
|---|
| 134 | imagefill ($dst_im, 0, 0, $transparent); |
|---|
| 135 | imagecolortransparent ($dst_im, $transparent); |
|---|
| 136 | } |
|---|
| 137 | $imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); |
|---|
| 138 | |
|---|
| 139 | if(function_exists("imagegif")) { |
|---|
| 140 | |
|---|
| 141 | // ²èÁü½ÐÎÏ |
|---|
| 142 | if($header){ |
|---|
| 143 | header("Content-Type: image/gif"); |
|---|
| 144 | imagegif($dst_im); |
|---|
| 145 | return ""; |
|---|
| 146 | }else{ |
|---|
| 147 | $dst_file = $dst_file . ".gif"; |
|---|
| 148 | imagegif($dst_im, $dst_file); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | imagedestroy($src_im); |
|---|
| 152 | imagedestroy($dst_im); |
|---|
| 153 | } else { |
|---|
| 154 | // ²èÁü½ÐÎÏ |
|---|
| 155 | if($header){ |
|---|
| 156 | header("Content-Type: image/png"); |
|---|
| 157 | imagepng($dst_im); |
|---|
| 158 | return ""; |
|---|
| 159 | }else{ |
|---|
| 160 | $dst_file = $dst_file . ".png"; |
|---|
| 161 | imagepng($dst_im, $dst_file); |
|---|
| 162 | } |
|---|
| 163 | imagedestroy($src_im); |
|---|
| 164 | imagedestroy($dst_im); |
|---|
| 165 | } |
|---|
| 166 | } else { |
|---|
| 167 | // ¥µ¥à¥Í¥¤¥ëºîÀ®ÉԲĤξì¹ç¡Êµì¥Ð¡¼¥¸¥ç¥óÂкö¡Ë |
|---|
| 168 | $dst_im = imageCreate($re_size[0], $re_size[1]); |
|---|
| 169 | imageColorAllocate($dst_im, 255, 255, 214); //ÇØ·Ê¿§ |
|---|
| 170 | |
|---|
| 171 | // ÏÈÀþ¤Èʸ»ú¿§¤ÎÀßÄê |
|---|
| 172 | $black = imageColorAllocate($dst_im, 0, 0, 0); |
|---|
| 173 | $red = imageColorAllocate($dst_im, 255, 0, 0); |
|---|
| 174 | |
|---|
| 175 | imagestring($dst_im, 5, 10, 10, "GIF $size[0]x$size[1]", $red); |
|---|
| 176 | imageRectangle ($dst_im, 0, 0, ($re_size[0]-1), ($re_size[1]-1), $black); |
|---|
| 177 | |
|---|
| 178 | // ²èÁü½ÐÎÏ |
|---|
| 179 | if($header){ |
|---|
| 180 | header("Content-Type: image/png"); |
|---|
| 181 | imagepng($dst_im); |
|---|
| 182 | return ""; |
|---|
| 183 | }else{ |
|---|
| 184 | $dst_file = $dst_file . ".png"; |
|---|
| 185 | imagepng($dst_im, $dst_file); |
|---|
| 186 | } |
|---|
| 187 | imagedestroy($src_im); |
|---|
| 188 | imagedestroy($dst_im); |
|---|
| 189 | } |
|---|
| 190 | break; |
|---|
| 191 | |
|---|
| 192 | // jpg·Á¼° |
|---|
| 193 | case "2": |
|---|
| 194 | |
|---|
| 195 | $src_im = imageCreateFromJpeg($path); |
|---|
| 196 | $dst_im = imageCreate($re_size[0], $re_size[1]); |
|---|
| 197 | //imageresized( $dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); |
|---|
| 198 | |
|---|
| 199 | // ²èÁü½ÐÎÏ |
|---|
| 200 | if($header){ |
|---|
| 201 | header("Content-Type: image/jpeg"); |
|---|
| 202 | imageJpeg($dst_im); |
|---|
| 203 | return ""; |
|---|
| 204 | }else{ |
|---|
| 205 | $dst_file = $dst_file . ".jpg"; |
|---|
| 206 | imageJpeg($dst_im, $dst_file); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | imagedestroy($src_im); |
|---|
| 210 | imagedestroy($dst_im); |
|---|
| 211 | |
|---|
| 212 | break; |
|---|
| 213 | |
|---|
| 214 | // png·Á¼° |
|---|
| 215 | case "3": |
|---|
| 216 | |
|---|
| 217 | $src_im = imageCreateFromPNG($path); |
|---|
| 218 | |
|---|
| 219 | $colortransparent = imagecolortransparent($src_im); |
|---|
| 220 | if ($colortransparent > -1) { |
|---|
| 221 | $dst_im = $imagecreate($re_size[0], $re_size[1]); |
|---|
| 222 | imagepalettecopy($dst_im, $src_im); |
|---|
| 223 | imagefill($dst_im, 0, 0, $colortransparent); |
|---|
| 224 | imagecolortransparent($dst_im, $colortransparent); |
|---|
| 225 | imagecopyresized($dst_im,$src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); |
|---|
| 226 | } else { |
|---|
| 227 | $dst_im = $imagecreate($re_size[0], $re_size[1]); |
|---|
| 228 | imagecopyresized($dst_im,$src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); |
|---|
| 229 | |
|---|
| 230 | (imagecolorstotal($src_im) == 0) ? $colortotal = 65536 : $colortotal = imagecolorstotal($src_im); |
|---|
| 231 | |
|---|
| 232 | imagetruecolortopalette($dst_im, true, $colortotal); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | // ²èÁü½ÐÎÏ |
|---|
| 236 | if($header){ |
|---|
| 237 | header("Content-Type: image/png"); |
|---|
| 238 | imagepng($dst_im); |
|---|
| 239 | return ""; |
|---|
| 240 | }else{ |
|---|
| 241 | $dst_file = $dst_file . ".png"; |
|---|
| 242 | imagepng($dst_im, $dst_file); |
|---|
| 243 | } |
|---|
| 244 | imagedestroy($src_im); |
|---|
| 245 | imagedestroy($dst_im); |
|---|
| 246 | |
|---|
| 247 | break; |
|---|
| 248 | |
|---|
| 249 | default: |
|---|
| 250 | return array(0, "¥¤¥á¡¼¥¸¤Î·Á¼°¤¬ÉÔÌÀ¤Ç¤¹¡£"); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | return array(1, $dst_file); |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| 256 | ?> |
|---|