Image resize codeigniter issue not working -
i've been attempting resize images no luck! have resize inside upload function not sure happening wrong! code below shows upload function (and resize within it):
function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '2048'; $this->load->library('image_lib', $config); $this->load->library('upload', $config); $fullimagepath = ''; if (! $this->upload->do_upload()) { $this->upload->display_errors('<p style="color: maroon; font-size:large;">', '</p>'); $error = array('file_error' => $this->upload->display_errors()); // print_r($error); $this->load->view('layout/header'); $this->load->view('add_gallery', $error); $this->load->view('layout/footer'); }else{ //echo "upload success"; // set $_post value 'image' can use later /*image manipulation class*/ $config['image_library'] = 'gd2'; $config['source_image'] = $fullimagepath; echo $fullimagepath; $config['create_thumb'] = false; $config['maintain_ratio'] = true; $config['max_width'] = '480'; $config['max_height'] = '640'; $this->load->library('image_lib', $config); $this->image_lib->resize(); $upload_data = $this->upload->data(); $fullimagepath = '/uploads/' . $upload_data['file_name']; } return $fullimagepath; }
the upload works fine , fullimagepath (link) store in database. anyway, not sure how handle resize.
the resize()
function requires first have configured source_image
before calling it, can apply resize specified image.
you sending empty path. here declare path empty string $fullimagepath = '';
, here define configuration options $config['source_image'] = $fullimagepath;
, after call $this->image_lib->resize();
, can not resize empty image.
also loading twice image_lib
not needed.
i modified code. test , see if works
function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; $config['max_size'] = '2048'; $this->load->library('upload', $config); $fullimagepath = ''; if (! $this->upload->do_upload()){ $this->upload->display_errors('<p style="color: maroon; font-size:large;">', '</p>'); $error = array('file_error' => $this->upload->display_errors()); $this->load->view('layout/header'); $this->load->view('add_gallery', $error); $this->load->view('layout/footer'); }else{ $upload_data = $this->upload->data(); $fullimagepath = '/uploads/' . $upload_data['file_name']; $config['image_library'] = 'gd2'; $config['source_image'] = $fullimagepath; $config['create_thumb'] = false; $config['maintain_ratio'] = true; $config['max_width'] = '480'; $config['max_height'] = '640'; $config['width'] = 75; $config['height'] = 50; $this->load->library('image_lib', $config); $this->image_lib->resize(); } return $fullimagepath; }
Comments
Post a Comment