php - How to resize image using Codeigniter -


i trying upload image , resizing image.i want both image original image thumb image.

but problem image resizing code not working.

image uploading code working fine store image in folder image resizing code not working.

how can ?

here code

public function add_images(){      $this->form_validation->set_rules('description','description','required');     $this->form_validation->set_rules('status','status','required');      if($this->form_validation->run() == true) {          // print_r($this->input->post());         $config['upload_path'] = 'public/img/inner_images/';         $config['allowed_types'] = 'gif|jpg|jpeg|png';   // upload valid images                     // update library setting of upload         $this->load->library('upload', $config);         //upload image          $this->upload->do_upload('image');         $finfo = $this->upload->data(); // info of uploaded file          //for image resize         $img_array = array();         $img_array['image_library'] = 'gd2';         $img_array['maintain_ratio'] = true;         $img_array['create_thumb'] = true;         //you need setting tell image lib image process         $img_array['source_image'] = $finfo['full_path'];         $img_array['width'] = 113;         $img_array['height'] = 75;          $this->load->library('image_lib', $img_array);          if (!$this->image_lib->resize())         {             echo $this->image_lib->display_errors(); exit;         }          if($finfo['file_ext'] ==='.gif'||$finfo['file_ext'] ==='.jpg'|| $finfo['file_ext'] ==='.jpeg' || $finfo['file_ext'] ==='.png'|| $finfo['file_ext'] ===''){             $insert = array(                 'inner_image' =>$finfo['file_name'],                 'description' => $this->input->post('description'),                 'status' => $this->input->post('status')             );             $check = $this->mdl_inner->add_image($insert);             if($check){                 $this->session->set_flashdata('success',"image added sucessfully");                 redirect('admin/inner_gallery/add_images/', 'refresh');               }         }else{             $this->session->set_flashdata('error',"upload proper image format");             redirect('admin/inner_gallery/add_images/', 'refresh');         }     }     $arrdata['middle'] = 'admin/inner/add_image';     $this->load->view('admin/template',$arrdata); } 

thanks guys solve problem. via loading library in constructor

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

after added 2 line code

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

and remove line

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

my final code

public function add_images(){      $this->form_validation->set_rules('description','description','required');     $this->form_validation->set_rules('status','status','required');      if($this->form_validation->run() == true) {          // print_r($this->input->post());         $config['upload_path'] = 'public/img/inner_images/';         $config['allowed_types'] = 'gif|jpg|jpeg|png';   // upload valid images                     // update library setting of upload         $this->load->library('upload', $config);         //upload image          $this->upload->do_upload('image');         $finfo = $this->upload->data(); // info of uploaded file          //for image resize         $img_array = array();         $img_array['image_library'] = 'gd2';         $img_array['maintain_ratio'] = true;         $img_array['create_thumb'] = true;         //you need setting tell image lib image process         $img_array['source_image'] = $finfo['full_path'];         $img_array['width'] = 113;         $img_array['height'] = 75;          $this->image_lib->clear(); // added line         $this->image_lib->initialize($img_array); // added line         if (!$this->image_lib->resize())         {             echo $this->image_lib->display_errors(); exit;         }         if($finfo['file_ext'] ==='.gif'||$finfo['file_ext'] ==='.jpg'|| $finfo['file_ext'] ==='.jpeg' || $finfo['file_ext'] ==='.png'|| $finfo['file_ext'] ===''){             $insert = array(                 'inner_image' =>$finfo['file_name'],                 'description' => $this->input->post('description'),                 'status' => $this->input->post('status')             );             $check = $this->mdl_inner->add_image($insert);             if($check){                 $this->session->set_flashdata('success',"image added sucessfully");                 redirect('admin/inner_gallery/add_images/', 'refresh');               }         }else{             $this->session->set_flashdata('error',"upload proper image format");             redirect('admin/inner_gallery/add_images/', 'refresh');         }     }     $arrdata['middle'] = 'admin/inner/add_image';     $this->load->view('admin/template',$arrdata); } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -