IMAGE SIZE REDUCTION IN CODEIGNITER
While uploading the image if the size of the image is high and we are using the software from the phone we need a much smaller size image, so while uploading the image the size reduction can be done. :
Code to put in Model:
$this->load->library('image_lib');
$config['upload_path']= 'upload/';
$config['allowed_types']='gif|jpg|png|jpeg|bmp';
$config['max_size']= '0'; //no limit for image size
$config['file_name'] = '';
$this->load->library('upload', $config);
$_FILES['file']['name'] = $image1['name'];
$_FILES['file']['type'] = $image1['type'];
$_FILES['file']['tmp_name'] = $image1['tmp_name'];
$_FILES['file']['error'] = $image1['error'];
$_FILES['file']['size'] = $image1['size'];
if ($this->upload->do_upload('file')) {
$imagename = $this->upload->data();
$configer = array(
'image_library' => 'gd2',
'source_image' => $imagename['full_path'],
'maintain_ratio' => TRUE,
'width' => 250,
'height' => 250,
);
$this->image_lib->clear();
$this->image_lib->initialize($configer);
$this->image_lib->resize();
} else {
$this->session->set_flashdata('error', $this->upload->display_errors());
redirect('add_form' );
}
$config['upload_path']= 'upload/';
$config['allowed_types']='gif|jpg|png|jpeg|bmp';
$config['max_size']= '0'; //no limit for image size
$config['file_name'] = '';
$this->load->library('upload', $config);
$_FILES['file']['name'] = $image1['name'];
$_FILES['file']['type'] = $image1['type'];
$_FILES['file']['tmp_name'] = $image1['tmp_name'];
$_FILES['file']['error'] = $image1['error'];
$_FILES['file']['size'] = $image1['size'];
if ($this->upload->do_upload('file')) {
$imagename = $this->upload->data();
$configer = array(
'image_library' => 'gd2',
'source_image' => $imagename['full_path'],
'maintain_ratio' => TRUE,
'width' => 250,
'height' => 250,
);
$this->image_lib->clear();
$this->image_lib->initialize($configer);
$this->image_lib->resize();
} else {
$this->session->set_flashdata('error', $this->upload->display_errors());
redirect('add_form' );
}