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

时间:2013-06-04 10:04:39

标签: 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;
    }

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

4 个答案:

答案 0 :(得分:11)

在我的项目中我遇到了类似的问题。这link帮我解决了。

替换

$this->load->library('image_lib', $config);

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

答案 1 :(得分:5)

更改您的第一行:

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

为:

$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);

答案 2 :(得分:0)

如果无效(我的情况),错误可能实际上是整个问题。

  1. 检查你是否安装了gd,在Linux上你会做

    sudo yum list安装| grep php

  2. 如果未安装,请安装

    sudo yum install php-gd-package-name

  3. 重新启动你的apache

    sudo service httpd restart

答案 3 :(得分:0)

我仍然显示了以上所有设置

“您的服务器不支持处理此类图像所需的GD功能。”

我进行了一些研究,以重新安装或修复php-gd库的安装。 您可以通过发出以下命令来做到这一点:

sudo apt-get install php7.1-gd

完成后,我重新启动了apache2

sudo service apache2 restart

效果很好。

您可以根据计算机上安装的PHP版本更改php7.1-gd