2012-04-11 85 views
1

我想創建用戶上傳的圖像的兩個縮略圖。我重複了兩次代碼,稍微改變了第二個縮略圖的配置,但是我只獲得了第一個創建的縮略圖,而第二個縮略圖沒有創建。下面是代碼:無法使用codeigniter創建圖像的兩個縮略圖

//First Thumbnail 
$conf['image_library'] = 'gd2'; 
$conf['source_image'] = "images/photos/123.jpg"; 
$conf['create_thumb'] = TRUE; 
$conf['thumb_marker'] = "_1"; 
$conf['maintain_ratio'] = true; 
$conf['width'] = 150; 
$conf['height'] = 150; 
$this->load->library('image_lib', $conf); 
$this->image_lib->resize(); 

//Second smaller Thumbnail 
$conf2['image_library'] = 'gd2'; 
$conf2['source_image'] = "images/photos/123.jpg"; 
$conf2['create_thumb'] = TRUE; 
$conf2['thumb_marker'] = "_2"; 
$conf2['maintain_ratio'] = true; 
$conf2['width'] = 50; 
$conf2['height']  = 50; 
$this->load->library('image_lib', $conf2); 
$this->image_lib->resize(); 

出於某種原因,第二部分從來沒有在所有工作和第一部分運作良好單獨以及與第二部分。我想我不應該在同一個地方加載兩次圖書館。我能做些什麼來解決這個問題?

回答

4

你需要清除庫之間,使用此:

$this->image_lib->clear(); 

,如果清算和重裝不起作用,你可以嘗試只用初始化函數替換第二庫加載由於某種原因未在ci_documentation中提及:

$this->image_lib->clear(); 
$this->image_lib->initialize($conf2);