gpt4 book ai didi

php - 在 Codeigniter 中压缩图像

转载 作者:行者123 更新时间:2023-12-04 07:31:53 25 4
gpt4 key购买 nike

我正在尝试压缩和调整上传的每个图像的大小。图像没有被压缩,而是以原始尺寸上传。我想通过设置 quality=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');
}

最佳答案

这里有些事情是乱序的。
首先上传图片,然后初始化resize,然后resize

$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();
}

关于php - 在 Codeigniter 中压缩图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67897987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com