12

我已经完成了图像上传,在 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

4 回答 4

13

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

代替

$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();
于 2014-03-07T16:11:46.830 回答
6

改变你的第一行:

$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);
于 2013-06-04T10:14:48.917 回答
1

我有所有上述设置仍然显示我

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

我进行了一些研究以重新安装或修复php-gd库的安装。您可以通过发出以下命令来执行此操作:

sudo apt-get install php7.1-gd

完成后,我重新启动了 apache2

sudo service apache2 restart

它工作得很好。

您可以php7.1-gd根据您机器上安装的 PHP 版本进行更改。

于 2020-04-19T09:05:02.423 回答
0

如果没有任何效果(我的情况),则错误实际上可能是整个问题。

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

    sudo yum 列表已安装 | grep php

  2. 如果没有安装,安装它

    sudo yum install php-gd-package-name

  3. 重新启动你的 apache

    sudo 服务 httpd 重启

于 2016-06-11T20:44:13.523 回答