I am trying to Compress and resize every image uploded. The image is not getting compressed, but its uploading in original dimensions. I want to reduce the size, by setting quality=60 and also set width to 100 to resize the image.
function save_order()
{
$data = $this->input->post(array('order_id', 'order_type', 'customer_id', 'order_total', 'payment_received', 'bill_no', 'pickup_date', 'delivery_date', 'pickups', 'designer', 'balance', 'remark', 'bill_img'));
if($_FILES["bill_img"])
{
$ext = pathinfo($_FILES['bill_img']['name'], PATHINFO_EXTENSION);
$filename_without_extension=explode('.'.$ext,$_FILES['bill_img']['name']);
$filename1=str_replace(' ','_',$filename_without_extension[0]);
$final_filename=str_replace('.','_',$filename1);
$filename=$final_filename.'.'.$ext;
$folder_name=$data['order_id'];
$config['upload_path'] ='./uploads/order/'.$folder_name;
if (!is_dir('./uploads/order/'.$folder_name))
{mkdir('./uploads/order/'.$folder_name, 0777, TRUE);}
$config['allowed_types'] = 'jpg|jpeg|png';
$config['file_name']=$filename;
$config['quality'] = '60%';
$config['width'] = 100;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->upload->initialize($config);
$do_upload1 = $this->upload->do_upload('bill_img');
if(!empty($do_upload1))
{$measur1 = 'uploads/order/'.$folder_name.'/'.$filename;
}
else{$measur1 = ""; }
}
$insert_data = array('order_type' => $data['order_type'], 'customer' => $data['customer_id'], 'pickups' => $data['pickups'],
'bill_no' => $data['bill_no'], 'pickup_date' => $data['pickup_date'], 'delivery_date' => $data['delivery_date'],
'designer' => $data['designer'], 'total_amt' => $data['order_total'] + $data['pickups'], 'received_amt' => $data['payment_received'], 'remaining_amt' => $data['balance'], 'remark' => $data['remark'], 'bill_img' => $measur1, 'created_at' => DATE);
$result = $this->common_model->insert_data('tbl_orders',$insert_data);
if($result)
{
$this->session->set_flashdata('success', 'Order Put Successfully.');
}
else{$this->session->set_flashdata('error','Opps.!!, Error While Putting Order.');}
redirect('manage-orders');
}