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

时间:2018-07-04 17:52:40

标签: codeigniter codeigniter-3 gd image-compression gd2

enter image description here

我正在尝试借助GD2图像压缩库在codeigniter中压缩图像大小,但显示错误

Your server must support the GD image library in order to determine the image properties.

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

但是在我的服务器上,它显示已启用GD

array(12) { ["GD Version"]=> string(26) "bundled (2.1.0 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(true) ["XBM Support"]=> bool(true) ["WebP Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }

这是我的代码

$file_path = './public/order_images/';
        if($_FILES['image_name']['name']!="")
        {
            $config['upload_path']          = $file_path;
            $config['allowed_types']        = 'gif|jpg|png';
            // $config['max_size']             = 1000000;
            // print_r($config);exit;
            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if (!$this->upload->do_upload('image_name'))
            {
                $error = array('error' => $this->upload->display_errors());
                // print_r($error);exit;
            }
            else
            {

                $data = array('upload_data' => $this->upload->data());
                $zfile = $data['upload_data']['full_path']; // get file path
                chmod($zfile,0777); // CHMOD file

                $img_config['image_library']          = 'gd2';
                $img_config['source_image']          = $data['upload_data']['full_path'];
                $img_config['create_thumb']        = FALSE;
                $img_config['maintain_ratio']             = TRUE;
                $img_config['quality']             = '60%';
                $img_config['width']             = 150;
                $img_config['height']             = 75;
                $img_config['new_image']             = $_SERVER['DOCUMENT_ROOT'].'/public/order_new_img/new_'.$data['upload_data']['file_name'];
                // $this->resize($file_path,$data['upload_data']['file_name']);
                $size = filesize($data['upload_data']['full_path']);
                // pre($img_config);
                var_dump(gd_info());

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

                $this->image_lib->initialize($img_config);

                // $this->image_lib->resize();

                // pre(getimagesize($data['upload_data']['full_path']));
                if (!$this->image_lib->resize()){

                        echo $this->image_lib->display_errors();exit;

                    } else {

                        echo "done";exit;

                    }
                $this->image_lib->clear();
            }

            $image_name = $data['upload_data']['file_name'];
        }

我还检查了php.info,它也显示了启用的GD,但是当我单击“提交”按钮时,此错误显示

GD不支持

请帮助我找到解决方法

感谢您进阶

0 个答案:

没有答案