Main($_GET["path"], $_GET["mw"], $_GET["mh"]); if(!$Ck) { // エラーの場合 header("Content-Type: text/html; charset=euc-jp"); print $Msg; } class gdthumb { function Main($Path, $MW, $MH) { // <-----スクリプトの設定-----> // 画像の最大横幅(デフォルト値) // 1以上の値を設定して下さい。 $imgMaxWidth = 800; // 画像の最大縦幅(デフォルト値) // 指定しない場合は0、指定する場合は1以上の値を設定して下さい。 $imgMaxHeight = 0; // GDのバージョン(0 = 2.0以前 / 1 = 2.0以降) $gdVer = 1; // <-----スクリプトの設定ここまで-----> if(!isset($Path)) { return array(0, "イメージのパスが設定されていません。"); exit; } if(!file_exists($Path)) { return array(0, "指定されたパスにファイルが見つかりません。"); exit; } // 画像の大きさをセット if($MW) $imgMaxWidth = $MW; if($MH) $imgMaxHeight = $MH; $size = @GetImageSize($Path); $re_size = $size; //アスペクト比固定処理 $tmp_w = $size[0] / $imgMaxWidth; if($imgMaxHeight != 0){ $tmp_h = $size[1] / $imgMaxHeight; } if($tmp_w > 1 || $tmp_h > 1){ if($imgMaxHeight == 0){ if($tmp_w > 1) { $re_size[0] = $imgMaxWidth; $re_size[1] = $size[1] * $imgMaxWidth / $size[0]; } } else { if($tmp_w > $tmp_h){ $re_size[0] = $imgMaxWidth; $re_size[1] = $size[1] * $imgMaxWidth / $size[0]; } else { $re_size[1] = $imgMaxHeight; $re_size[0] = $size[0] * $imgMaxHeight / $size[1]; } } } switch($size[2]): // gif形式 case "1": // 画像のサイズが指定サイズ以下だった場合はそのまま出力 if($tmp_w <= 1 && $tmp_h <= 1) { print readfile($Path); break; } // 指定サイズ以上だった場合は、画像情報を出力 $imgNew = imagecreate($re_size[0], $re_size[1]); ImageColorAllocate($imgNew, 255, 255, 214); //背景色 // 枠線と文字色の設定 $black = ImageColorAllocate($imgNew, 0, 0, 0); $red = ImageColorAllocate($imgNew, 255, 0, 0); Imagestring($imgNew, 5, 10, 10, "GIF $size[0]x$size[1]", $red); ImageRectangle ($imgNew, 0, 0, ($re_size[0]-1), ($re_size[1]-1), $black); header("content-Type: image/png"); ImagePNG($imgNew); ImageDestroy($imgNew); break; // jpg形式 case "2": //GDバージョン判定 if(GDVer){ $imgNew = imagecreatetruecolor($re_size[0], $re_size[1]); $imgDef = imagecreatefromjpeg($Path); ImageCopyResampled( $imgNew, $imgDef, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } else { $imgNew = imagecreate($re_size[0], $re_size[1]); $imgDef = imagecreateFromJpeg($Path); ImageCopyResized( $imgNew, $imgDef, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } header("content-Type: image/jpeg"); ImageJpeg($imgNew); ImageDestroy($imgDef); ImageDestroy($imgNew); break; // png形式 case "3": //GDバージョン判定 if(GDVer){ $imgNew = imagecreatetruecolor($re_size[0], $re_size[1]); $imgDef = imagecreateFromPng($Path); ImageCopyResampled( $imgNew, $imgDef, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } else { $imgNew = imagecreate($re_size[0], $re_size[1]); $imgDef = imagecreateFromPng($Path); ImageCopyResized( $imgNew, $imgDef, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } header("content-Type: image/png"); ImagePNG($imgNew); ImageDestroy($imgDef); ImageDestroy($imgNew); break; default: return array(0, "イメージの形式が不明です。"); exit; endswitch; return array(1,""); } } ?>