我基本上試圖做的是將圖像調整爲兩個不同大小的圖像。不過,我只能調整第一個featured_$filename
,我無法調整thumb_$filename
的大小。Codeigniter圖像調整大小隻調整一個圖像
最初我嘗試創建一個單一的功能,並將配置作爲一個數組傳遞,它沒有工作,但同樣的事情,只調整了單個圖像。
$this->resizeImage($imagePath, $file['upload_data']['file_name']);
$this->resizeThumb($imagePath, $file['upload_data']['filename']);
public function resizeImage($imagePath, $filename){
$config['image_library'] = 'gd2';
$config['source_image'] = $imagePath;
$config['create_thumb'] = FALSE;
$config['new_image'] = 'featured_'.$filename;
$config['maintain_ratio'] = TRUE;
$config['width'] = 570;
$config['height'] = 372;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
}
public function resizeThumb($imagePath, $filename){
$config['image_library'] = 'gd2';
$config['source_image'] = $imagePath;
$config['create_thumb'] = FALSE;
$config['new_image'] = 'thumb_'.$filename;
$config['maintain_ratio'] = TRUE;
$config['width'] = 180;
$config['height'] = 135;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
}
格式很好的答案。一旦我檢查,我會接受答案。謝謝 。 – prakashchhetri
它適合你嗎? –