协调员:GD库已安装在服务器上但显示您的服务器不支持处理此类图像所需的GD功能

时间:2018-05-05 05:23:16

标签: gd

我已经在服务器上安装了 GD库,但如果我上传的图片格式为images = UserProfile.objects.filter(user=user) validatedimages = None for image in images: if bool(image.image) == True: validatedimages = validatedimages.append(image.image) profileimages = validatedimages ,则会显示错误jpg,png,jpeg 如果安装了GD库,为什么要显示这些类型的错误?

"Your server does not support the GD function required to process this type of image."

1 个答案:

答案 0 :(得分:0)

您正在传递$this->upload->file_name未知值。 GD库无法找到您传递给$photo进行验证的字符串/对象的图像格式和扩展名。

您应该使用$this->upload->data()来捕获上传的图像值,如下所示。

$config = [
    'upload_path' => $this->upload_path, // make sure you are adding tailing `/` in your upload path, else you should add `/` before joing the images below
    'allowed_types' => $this->image_types,
    'max_size' => $this->allowed_file_size,
    'max_width' => $this->Settings->iwidth,
    'max_height' => $this->Settings->iheight,
    'overwrite' => false,
    'encrypt_name' => true,
    'max_filename' => 25
];
$this->load->library('upload', $config);  // make sure you are loading the `upload` library, else it will load
$this->upload->initialize($config);             
if($this->upload->do_upload('product_image')){  
    $uploaded_data = $this->upload->data(); // here you should collect the uploaded data    
    $data['image'] = $uploaded_data['file_name'];   
    $config = [
        'image_library' => 'gd2',
        'source_image' => $this->upload_path . $uploaded_data['file_name'],
        'new_image' => $this->thumbs_path . $uploaded_data['file_name'],
        'maintain_ratio' => true,
        'width' => $this->Settings->twidth,
        'height' => $this->Settings->theight,
        'quality' => '100%',
    ];
    $this->load->library('image_lib', $config);
    $this->image_lib->initialize($config);
    if ($this->image_lib->resize()){
        return true;
    }else{
        return $this->image_lib->display_errors();
    }   
}else{
    $this->session->set_flashdata('error', $this->upload->display_errors());
    redirect("products/edit/" . $id);
}