tmp_dir = $tmp_dir . "/"; } else { $this->tmp_dir = $tmp_dir; } } //--- 一時ファイル生成(サムネイル画像生成用) function makeTempImage($keyname, $max_width, $max_height) { // 一意なIDを取得する。 $mainname = uniqid("")."."; // 拡張子以外を置き換える。 $newFileName = ereg_replace("^.*\.",$mainname, $_FILES[$keyname]['name']); $result = MakeThumb($_FILES[$keyname]['tmp_name'], $this->tmp_dir , $max_width, $max_height, $newFileName); gfDebugLog($result); return $newFileName; } //--- ファイルを指定保存DIRへ移動 function moveTempImage($filename, $save_dir) { // コピー元ファイル、コピー先ディレクトリが存在する場合にのみ実行する if(file_exists($this->tmp_dir.$filename) && file_exists($save_dir)) { if(copy($this->tmp_dir . $filename , $save_dir."/".$filename)) { unlink( $this->tmp_dir . $filename ); } } else { gfDebugLog($this->tmp_dir.$filename."の移動に失敗しました。"); } } //---- 指定ファイルを削除 function deleteImage($filename, $dir) { if(file_exists($dir."/".$filename)) { unlink($dir."/".$filename); } } // 拡大率を指定して画像保存 function saveResizeImage($file, $to_w = 0, $to_h = 0, $header = false) { // ディレクトリ取得 $dir = dirname($file); // 元画像サイズを取得 list($from_w, $from_h) = getimagesize($file); if($to_w > 0 or $to_h > 0){ // 幅の縮小率 ($to_w < $from_w) ? $wscale = $to_w / $from_w : $wscale = 1; // 高さの縮小率 ($to_h < $from_h) ? $hscale = $to_h / $from_h : $hscale = 1; // 縮小率は小さいほうにあわせる ($wscale < $hscale) ? $scale = $wscale : $scale = $hscale; }else{ $scale = 1; } // 圧縮率指定 $zip_width = $from_w * $scale; $zip_height = $from_h * $scale; // ファイルの拡張子取得 $arrFileInfo = pathinfo($file); $extension = $arrFileInfo["extension"]; // 一意なIDを取得する。 $uniqname = date("mdHi") . "_" . uniqid(""); // ファイル名、保存先設定 $filename = $uniqname . "." . $extension; $path = $dir . "/" . $filename; // ファイルの拡張子によって処理を分ける if(is_dir($dir)) { switch ($extension) { case "jpg": case "jpeg": //元画像 $src_im = ImageCreateFromJPEG($file); // 圧縮先画像 $dst_im = imagecreatetruecolor($zip_width, $zip_height); imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $from_w, $from_h); // 画像出力 if($header){ header("Content-Type: image/jpeg"); ImageJPEG($dst_im); }else{ ImageJPEG($dst_im, $path); } break; case "gif": //元画像 $src_im = ImageCreateFromGIF($file); // 圧縮先画像 $dst_im = imagecreatetruecolor($zip_width, $zip_height); imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $from_w, $from_h); // 画像出力 if($header){ header("Content-Type: image/gif"); ImageGIF($dst_im); }else{ ImageGIF($dst_im, $path); } break; case "png": //元画像 $src_im = ImageCreateFromPNG($file); // 圧縮先画像 $dst_im = imagecreatetruecolor($zip_width, $zip_height); imagecopyresampled($dst_im, $src_im, 0, 0, 0,0, $zip_width, $zip_height, $from_w, $from_h); // 画像出力 if($header){ header("Content-Type: image/png"); ImagePNG($dst_im); }else{ ImagePNG($dst_im, $path); } break; default: print("拡張子が不正です。"); $path = ""; break; } ImageDestroy($src_im); ImageDestroy($dst_im); if(!$header){ return $path; }else{ return ""; } } print("画像の保存に失敗しました。"); return ""; } } ?>