私は友人が彼自身の芸術的なギャラリーを作るのを手伝う必要があります。私はすでにすべてを完了しましたが、彼自身の画像をアップロードする際に彼を私から独立させるためのツール/プラグイン/スクリプトが必要です。私のギャラリーには2つの画像が必要です。特定の比率のトリミングされた画像(アップロードページで自分でトリミングする必要があるため)と親指の画像(これを自動的に実行する必要があります)です。
これを行う簡単な方法を知っていますか?あなたならどうしますか?
ありがとう。
開始するトラフィックがそれほど多くない場合は、http://phpthumb.sourceforge.net/を参照してください。これにより、サイズ変更された画像をその場で作成できます。
個人的には、これをすべてのプロジェクトで使用しています-http : //www.verot.net/php_class_upload.htmアップロードファイルおよびシステム上にすでに存在するファイルで完全に機能します。
アップロードされた画像をさまざまな方法で変換、サイズ変更、操作したり、効果を適用したり、ラベル、透かし、反射、その他の画像編集機能を追加したりすることができます。
取り扱いが簡単です。
必要なのはGDライブラリだけで、関数imagecopyresampledが適しています。PHPマニュアルには、サムネイル作成のための非常に優れたサンプルコードがありますhttp://php.net/manual/en/function.imagecopyresampled.php さまざまなファイル形式の例外を作成するだけで済みます。
function create_jpeg_thumbnail($thumbImageName,$imgSrc,$thumbDirectory,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
$thumbDirectory = trim($thumbDirectory);
$imageSourceExploded = explode('/', $imgSrc);
$imageName = $imageSourceExploded[count($imageSourceExploded)-1];
$imageDirectory = str_replace($imageName, '', $imgSrc);
$filetype = explode('.',$imageName);
$filetype = strtolower($filetype[count($filetype)-1]);
//getting the image dimensions
list($width_orig, $height_orig) = getimagesize($imgSrc);
//$myImage = imagecreatefromjpeg($imgSrc);
if ($filetype == 'jpg') {
$myImage = imagecreatefromjpeg("$imageDirectory/$imageName");
} else
if ($filetype == 'jpeg') {
$myImage = imagecreatefromjpeg("$imageDirectory/$imageName");
} else
if ($filetype == 'png') {
$myImage = imagecreatefrompng("$imageDirectory/$imageName");
} else
if ($filetype == 'gif') {
$myImage = imagecreatefromgif("$imageDirectory/$imageName");
}
$ratio_orig = $width_orig/$height_orig;
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
$new_height = $thumbnail_width/$ratio_orig;
$new_width = $thumbnail_width;
} else {
$new_width = $thumbnail_height*$ratio_orig;
$new_height = $thumbnail_height;
}
$x_mid = $new_width/2; //horizontal middle
$y_mid = $new_height/2; //vertical middle
$process = imagecreatetruecolor(round($new_width), round($new_height));
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
imagecopyresampled($thumb, $process, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
//$thumbImageName = 'thumb_'.get_random_no().'.jpeg';
$destination = $thumbDirectory=='' ? $thumbImageName : $thumbDirectory."/".$thumbImageName;
imagejpeg($thumb, $destination, 100);
return $thumbImageName;
}