Main($_GET["path"], $_GET["mw"], $_GET["mh"]); if(!$Ck) { // エラーの場合 header("Content-Type: text/html; charset=euc-jp"); print $Msg; } class gdthumb { var $imgMaxWidth; var $imgMaxHeight; var $gdVer; /* * コンストラクタ */ function gdthumb() { // スクリプトのデフォルト設定 // 画像の最大横幅 $this->imgMaxWidth = 240; // 1以上の値 // 画像の最大縦幅 $this->imgMaxHeight = 260; // 指定しない場合は0 指定する場合は1以上の値 } /* * サムネイル画像の作成 * string $path * integer $width * integer $height */ function Main($path, $width, $height) { if(!isset($path)) { return array(0, "イメージのパスが設定されていません。"); exit; } if(!file_exists($path)) { return array(0, "指定されたパスにファイルが見つかりません。"); exit; } // 画像の大きさをセット if($width) $this->imgMaxWidth = $width; if($height) $this->imgMaxHeight = $height; $size = @GetimageSize($path); $re_size = $size; //アスペクト比固定処理 $tmp_w = $size[0] / $this->imgMaxWidth; if($this->imgMaxHeight != 0) { $tmp_h = $size[1] / $this->imgMaxHeight; } if($tmp_w > 1 || $tmp_h > 1) { if($this->imgMaxHeight == 0) { if($tmp_w > 1) { $re_size[0] = $this->imgMaxWidth; $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0]; } } else { if($tmp_w > $tmp_h) { $re_size[0] = $this->imgMaxWidth; $re_size[1] = $size[1] * $this->imgMaxWidth / $size[0]; } else { $re_size[1] = $this->imgMaxHeight; $re_size[0] = $size[0] * $this->imgMaxHeight / $size[1]; } } } $imagecreate = function_exists("imagecreatetruecolor") ? "imagecreatetruecolor" : "imagecreate"; $imageresize = function_exists("imagecopyresampled") ? "imagecopyresampled" : "imagecopyresized"; switch($size[2]): // gif形式 case "1": // 画像のサイズが指定サイズ以下だった場合はそのまま出力 if($tmp_w <= 1 && $tmp_h <= 1) { echo readfile($path); break; } if(function_exists("imagecreatefromgif")) { $src_im = imagecreatefromgif($path); $dst_im = $imagecreate($re_size[0], $re_size[1]); $transparent = imagecolortransparent($src_im); $colorstotal = imagecolorstotal ($src_im); if(function_exists("imagecreatetruecolor")) { $dst_im = imagecreatetruecolor($re_size[0], $re_size[1]); $tc = imagecolorsforindex($src_im, $transparent); imagefill ($dst_im, 0, 0, imagecolorallocate ($dst_im, $tc["red"], $tc["green"], $tc["blue"])); imagetruecolortopalette ($dst_im, false, $colorstotal); imagecolortransparent ($dst_im, imagecolorclosest ($dst_im, $tc["red"], $tc["green"], $tc["blue"])); imagecopyresampled ($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } else { $dst_im = imagecreate($re_size[0], $re_size[1]); if (0 <= $transparent && $transparent < $colorstotal) { imagepalettecopy ($dst_im, $src_im); imagefill ($dst_im, 0, 0, $transparent); imagecolortransparent ($dst_im, $transparent); } imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } if(function_exists("imagegif")) { header("content-Type: image/gif"); imagegif($dst_im); imagedestroy($src_im); imagedestroy($dst_im); } else { header("content-Type: image/png"); imagepng($dst_im); imagedestroy($src_im); imagedestroy($dst_im); } } else { // サムネイル作成不可の場合(旧バージョン対策) $dst_im = imageCreate($re_size[0], $re_size[1]); imageColorAllocate($dst_im, 255, 255, 214); //背景色 // 枠線と文字色の設定 $black = imageColorAllocate($dst_im, 0, 0, 0); $red = imageColorAllocate($dst_im, 255, 0, 0); imagestring($dst_im, 5, 10, 10, "GIF $size[0]x$size[1]", $red); imageRectangle ($dst_im, 0, 0, ($re_size[0]-1), ($re_size[1]-1), $black); header("content-Type: image/png"); imagepng($dst_im); imagedestroy($src_im); imagedestroy($dst_im); } // jpg形式 case "2": $src_im = imageCreateFromJpeg($path); $dst_im = $imagecreate($re_size[0], $re_size[1]); $imageresize( $dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); header("content-Type: image/jpeg"); imageJpeg($dst_im); imagedestroy($src_im); imagedestroy($dst_im); break; // png形式 case "3": $src_im = imagecreatefrompng($path); $colortransparent = imagecolortransparent($src_im); if ($colortransparent > -1) { $dst_im = $imagecreate($re_size[0], $re_size[1]); imagepalettecopy($dst_im, $src_im); imagefill($dst_im, 0, 0, $colortransparent); imagecolortransparent($dst_im, $colortransparent); $imageresize($dst_im,$src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); } else { $dst_im = $imagecreate($re_size[0], $re_size[1]); $imageresize($dst_im,$src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]); imagetruecolortopalette($dst_im, false, imagecolorstotal($src_im)); } header("content-Type: image/png"); imagepng($dst_im); imagedestroy($src_im); imagedestroy($dst_im); break; default: return array(0, "イメージの形式が不明です。"); exit; endswitch; return array(1,""); } } ?>