1

ユーザーがアップロードした画像を取得し、3 つのコピーを作成する Web サイトがあります。印刷用の「フル」コピー (1500x1125 に縮小)、オンラインで表示するための「Web」コピー (まだコーディングされていません)、最後にサムネイルです。

コードは次のとおりです。_imageformat() には、CI のアップロード クラスからパラメーター (正しいことが確認済み) が渡されます。

function _imageformat($fullpath, $shortpath, $width, $height)

{ // 画像をフォーマットします。

// まず、横か縦かをチェックします if ($width >= $height) // 横 (または正方形) です、$fullpath、$shortpath、$width、$height); } else // 縦向きです { // では、完全な印刷イメージを作成します $fullimage = $this->_resize('p', $fullpath, $shortpath, $width, $height); }

}

function _resize($type, $fullpath, $shortpath, $width, $height) { // デフォルトの画像操作構成オプションを設定します $config['image_library'] = 'gd2'; $config['source_image'] = $fullpath; $config['maintain_ratio'] = TRUE;

// Shave the '.jpg' from the end to append some nice suffixes we'll use
$newimage = substr($fullpath, 0, -4).'_full'.".jpg";

$config['new_image'] = $newimage;

if ($type == 'l') // If it's landscape
{
 $config['width'] = 1500;
 $config['height'] = 1125;
}
else if ($type == 'p') // If it's portrait
{
 $config['width'] = 1125;
 $config['height'] = 1500;   
}

// Load the image library with the specified parameters, and resize the image!  
$this->load->library('image_lib', $config); 
$this->image_lib->resize();

// Create a thumbnail from the full image
$config['source_image']  = $newimage;
$config['new_image']  = substr($fullpath, 0, -9)."_thumb".".jpg";
$config['maintain_ratio']  = TRUE;
$config['width']    = 150;
$config['height']   = 150;

$this->load->library('image_lib', $config); 

$this->image_lib->resize();

return $newimage;

}

すべきこと:アップロード フォルダーには、元のアップロード ファイル (image.jpg と呼びます)、サイズ変更されたファイル (image_full.jpg という名前)、およびサムネイル (image_thumb.jpg という名前) の 3 つの画像があります。

何が起こるか:アップロード フォルダーには、元のアップロード ファイル (image.jpg) とサイズ変更されたファイル (image_full.jpg) の 2 つの画像しかありません。サムネイルは作成されません。

ただし、興味深いのは、** サムネイル作成用のコードを最初に配置すると、サムネイル画像が生成されますが、_full (サイズ変更された) 画像は生成されないことです。

したがって、2回実行されることはないように思えます$this->image_lib->resize()。なぜだめですか?私が犯しているアマチュアの間違いですか、それとも明らかな何かを見逃したのでしょうか?! :P

ありがとう!

ジャック

編集:image_libはい、ライブラリを2回ロードしていることを知っていることを指摘する必要があります。これが新しいパラメーターを渡す唯一の方法であることがわかりました。また、画像全体のサイズを変更した後$this->_thumbnail()、ライブラリを再度ロードした呼び出しを試みました。しかし、それでも同じ問題が発生しました。

編集2:私も使用してみました$this->image_lib->clear()-まだ運がありません。

4

1 に答える 1

2

ライブラリを一度だけロードし、異なる構成で初期化する必要があります。

$this->load->library('image_lib');

// full image stuff
$this->image_lib->initialize($config);
$this->image_lib->resize();

// thumbnail stuff
$this->image_lib->initialize($config);
$this->image_lib->resize();
于 2010-08-26T11:06:22.293 に答える