我正在尝试压缩并调整上传的每个图像的大小。图像没有被压缩,而是以原始尺寸上传。我想通过将质量设置为60并将宽度设置为100来缩小图像大小。
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');
}
有些事情不按顺序。首先,上传图像,然后初始化调整大小,然后调整大小
$do_upload1 = $this->upload->do_upload('bill_img');
if(!empty($do_upload1)) {
$measur1 = 'uploads/order/'.$folder_name.'/'.$filename;
// resize
$resize_config['image_library'] = 'gd2';
$resize_config['source_image'] = $do_upload1['file_path']; // full path to the image
$resize_config['maintain_ratio'] = true;
$resize_config['width'] = 100;
$resize_config['quality'] = '60%';
$this->load->library('image_lib', $resize_config);
$this->image_lib->resize();
}