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

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

我不明白发生了什么..??

最佳答案

改变你的第一行:

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

关于codeigniter - 您的服务器不支持处理此类图像所需的 GD 功能。Ci,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16915016/

相关文章:

codeigniter ion auth https 重定向无限循环

mysql - 数据表模型错误

php - 使用 where 线索计算数据库行数

php - Codeigniter - 由于数据不起作用而返回 View

mysql - 在 where 子句中获取未知列

php - 如何在 codeigniter 中对列中的数据进行切片并根据它进行排序?

php - 如何使用 PHP 和 MySQL 中的表单更新行位置?

php - 尝试在 Codeigniter 4 中启动分页时返回错误

php - Apache header 中的欧元字符

php - 具有事件记录或 dbforge 的 Codeigniter 克隆表