我一直在尝试调整图像大小,但没有运气!我在上传功能中有调整大小,但不确定发生了什么错误!下面的代码显示了我的上传功能(并在其中调整大小):
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 a $_POST value for 'image' that we 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;
}
上传工作正常,我将 fullImagePath(链接)存储在数据库中。无论如何,只是不确定如何处理调整大小。