[如果文件大小大于1MB,我正在使用代码调整图像的大小,我在模型函数中使用了此功能,但是它返回false。这里有什么问题。
if($_FILES[$name]['size']/(1024)>1024){
$upload_data = $this->upload->data();
$config2['image_library'] = 'ImageMagick';
$config2['source_image'] = $upload_data["file_path"];
$config2['create_thumb'] = TRUE;
$config2['maintain_ratio'] = TRUE;
$config2['quality'] = '60%';
$config2['width'] = 200;
$config2['height'] = 200;
//$config2['new_image'] = $upload_data["file_name"];
$this->load->library('image_lib', $config2);
$this->image_lib->clear();
$this->image_lib->initialize($config2);
var_dump($this->image_lib->resize());
}
您不应在if中加载image_lib。尝试使用下面的代码
$this->load->library('image_lib');
if($_FILES[$name]['size']/(1024)>1024){
$upload_data = $this->upload->data();
$config2['image_library'] = 'ImageMagick';
$config2['source_image'] = $upload_data["file_path"];
$config2['create_thumb'] = TRUE;
$config2['maintain_ratio'] = TRUE;
$config2['quality'] = '60%';
$config2['width'] = 200;
$config2['height'] = 200;
//$config2['new_image'] = $upload_data["file_name"];
$this->image_lib->clear();
$this->image_lib->initialize($config2);
var_dump($this->image_lib->resize());
}