Codeigniter 图像调整编码器点火器问题不起作用
我一直在尝试调整图像大小,但没有运气!我有在上传功能内调整大小,但不确定发生了什么错误!下面的代码显示了我的上传功能(并在其中调整大小):Codeigniter 图像调整编码器点火器问题不起作用,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,我一直在尝试调整图像大小,但没有运气!我有在上传功能内调整大小,但不确定发生了什么错误!下面的代码显示了我的上传功能(并在其中调整大小): 函数do_upload() { $config['upload_path']='./uploads/'; $config['allowed_types']='gif | jpg | png | jpeg'; $config['max_size']='2048'; $this->load->library('image_lib',$config); $this
函数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='';
如果(!$this->upload->do_upload())
{
$this->upload->display_错误('”,'
');
$error=array('file_error'=>$this->upload->display_errors());
//打印错误($error);
$this->load->view('layout/header');
$this->load->view('add_gallery',$error);
$this->load->view('layout/footer');
}否则{
//回声“上传成功”;
//为“image”设置一个$\u POST值,以便以后使用
/*图像处理类*/
$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'];
}
返回$fullImagePath;
}
上传工作正常,我得到了完整的ImagePath(链接)以存储在数据库中。无论如何,只是不知道如何处理调整大小 调用resize()
函数之前,需要先配置source\u图像
,以便将resize应用于指定的图像
您正在发送一条空路径。
在这里,您将路径声明为空字符串$fullImagePath=''
然后在这里将其定义为配置选项$config['source\u image']=$fullImagePath然后调用$this->image_lib->resize()代码>,因此无法调整为空图像的大小
此外,您正在加载两次不需要的图像库
我修改了你的代码。测试一下,看看是否有效
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$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());
$this->load->view('layout/header');
$this->load->view('add_gallery', $error);
$this->load->view('layout/footer');
}else{
$upload_data = $this->upload->data();
$fullImagePath = '/uploads/' . $upload_data['file_name'];
$config['image_library'] = 'gd2';
$config['source_image'] = $fullImagePath;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['max_width'] = '480';
$config['max_height'] = '640';
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
return $fullImagePath;
}
函数do_upload()
{
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png | jpeg';
$config['max_size']='2048';
$this->load->library('upload',$config);
$fullImagePath='';
如果(!$this->upload->do_upload()){
$this->upload->display_错误('”,'
');
$error=array('file_error'=>$this->upload->display_errors());
$this->load->view('layout/header');
$this->load->view('add_gallery',$error);
$this->load->view('layout/footer');
}否则{
$upload_data=$this->upload->data();
$fullImagePath='/uploads/'.$upload_data['file_name'];
$config['image_library']='gd2';
$config['source_image']=$fullImagePath;
$config['create_thumb']=FALSE;
$config['maintain_ratio']=TRUE;
$config['max_width']='480';
$config['max_height']='640';
$config['width']=75;
$config['height']=50;
$this->load->library('image_lib',$config);
$this->image_lib->resize();
}
返回$fullImagePath;
}
您的代码看起来是正确的。。使sute$fullImagePath
正确并指向您的imahe文件..不,这还不起任何作用。与上载的大小完全相同。请确保$fullImagePath
指向正确的路径。它与我使用的src到图像的路径相同。因此,是的,它是正确的,不是空的。我又添加了两个配置选项$config['width']=75代码>和$config['height']=50代码>。现在检查一下。
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$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());
$this->load->view('layout/header');
$this->load->view('add_gallery', $error);
$this->load->view('layout/footer');
}else{
$upload_data = $this->upload->data();
$fullImagePath = '/uploads/' . $upload_data['file_name'];
$config['image_library'] = 'gd2';
$config['source_image'] = $fullImagePath;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['max_width'] = '480';
$config['max_height'] = '640';
$config['width'] = 75;
$config['height'] = 50;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
return $fullImagePath;
}