2008-11-01 8 views
3

Je rencontre des problèmes pour manipuler des images avec CodeIgniter 1.7. Avec le code suivant, l'image est téléchargée correctement. Hélas, au lieu d'une nouvelle image faite, puis modifiée; l'image existante est modifiée. De l'aide?Manipulation d'image dans CodeIgniter

//Upload image first 
$config['upload_path'] = './uploads/'; 
$config['allowed_types'] = 'gif|jpg|png|bmp'; 

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

//Now fix the image 
$picloc = $this->upload->data(); 
$picloc = $picloc['file_name']; 

$thumbnail = "thumb_".$picloc; 

$imagemanip['image_library'] = 'gd2'; 
$imagemanip['source_image'] = './uploads/'.$picloc; 
$imagemanip['new_img'] = './uploads/'.$thumbnail; 
$imagemanip['maintain_ratio'] = TRUE; 
$imagemanip['width'] = 250; 
$imagemanip['height'] = 250; 

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

$this->image_lib->resize(); 

Répondre

4

Le problème est simple, vous avez une faute de frappe dans la ligne:

$imagemanip['new_img'] = './uploads/'.$thumbnail; 

L'indice devrait être "new_image", pas "new_img", de sorte que la ligne devient ..

$imagemanip['new_image'] = './uploads/'.$thumbnail; 
0
//Upload image first 
$config['upload_path'] = './uploads/'; 
$config['allowed_types'] = 'gif|jpg|png|bmp'; 

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

//Now fix the image 
$picloc = $this->upload->data(); 
$picloc = $picloc['file_name']; 

$thumbnail = "thumb_".$picloc; 

$imagemanip['image_library'] = 'gd2'; 
$imagemanip['source_image'] = './uploads/'.$picloc; 
$imagemanip['new_image'] = './uploads/'.$thumbnail;// this will get change in new code. 
$imagemanip['maintain_ratio'] = TRUE; 
$imagemanip['width'] = 250; 
$imagemanip['height'] = 250; 

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

$this->image_lib->resize(); 

maintenant cela va faire votre travail