您的服务器不支持处理此类图像所需的GD功能.Ci

Dru*_*jen 9 codeigniter

我已经完成了图像上传,在CI中重复了很多次.相同的代码在一个页面中工作,但在其他页面中不起作用.当我显示错误时,它显示"您的服务器不支持处理此类图像所需的GD功能." 上传图片的代码是...... \

 function do_upload() {

        $original_path = './uploads/activity_images/original';
        $resized_path = './uploads/activity_images/resized';
        $thumbs_path = './uploads/activity_images/thumb';
        $this->load->library('image_lib');

        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png', //only accept these file types
            'max_size' => 2048, //2MB max
            'upload_path' => $original_path //upload directory    
        );
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data(); //upload the image
        $image1 = $image_data['file_name'];

        //your desired config for the resize() function
        $config = array(
            'source_image' => $image_data['full_path'], //path to the uploaded image
            'new_image' => $resized_path,
            'maintain_ratio' => true,
            'width' => 128,
            'height' => 128
        );
        $this->image_lib->initialize($config);
        $this->image_lib->resize();

        // for the Thumbnail image
        $config = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $thumbs_path,
            'maintain_ratio' => true,
            'width' => 36,
            'height' => 36
        );
        //here is the second thumbnail, notice the call for the initialize() function again
        $this->image_lib->initialize($config);

        $this->image_lib->resize();
        //$this->image_lib->clear();
       echo  $this->image_lib->display_errors();
        var_dump(gd_info());
        die();
        return $image1;
    }
Run Code Online (Sandbox Code Playgroud)

发生了什么我无法理解.. ??

mri*_*dul 11

在我的项目中我遇到了类似的问题.这个链接帮助我解决它.

更换

$this->load->library('image_lib', $config);
Run Code Online (Sandbox Code Playgroud)

同

$this->load->library('image_lib');
// Set your config up
$this->image_lib->initialize($config);
// Do your manipulation
$this->image_lib->clear();
Run Code Online (Sandbox Code Playgroud)


Kee*_*ema 5

改变你的第一行:

$original_path = './uploads/activity_images/original';
$resized_path = './uploads/activity_images/resized';
$thumbs_path = './uploads/activity_images/thumb';
$this->load->library('image_lib');
Run Code Online (Sandbox Code Playgroud)

至:

$config['image_library'] = 'gd2';
$original_path = './uploads/activity_images/original';
$resized_path = './uploads/activity_images/resized';
$thumbs_path = './uploads/activity_images/thumb';
$this->load->library('image_lib', $config);
Run Code Online (Sandbox Code Playgroud)

  • 我刚刚发现自己,如果你没有提供有效图像文件的完整路径,CI会抛出此错误.如果缺少文件名,那么getimagesize()将返回false并导致错误.不太清楚...... (4认同)