dougao1542 2015-01-10 11:42
浏览 242

获取错误“您的服务器不支持处理此类图像所需的GD功能。”在CI中调整大小时

I am using CodeIgniter To upload as well as resize images. Using library image_lib and loading it in the following way. My upload is working fine but having problem with the php gd function. When printing the error it says, "Your server does not support the GD function required to process this type of image." I did not have gd enabled. I have restarted my xampp after enabling it. And still have the problem.

                //get the image sizes
                $image_sizes = $this->image_model->get_image_sizes();

                foreach ($image_sizes as $image_size) {
                    $this->load->library('image_lib');


                    $mod_config['image_library'] = 'gd2';
                    $mod_config['source_image'] = './uploads/';
                    $mod_config['create_thumb'] = TRUE;
                    $mod_config['maintain_ratio'] = TRUE;
                    $mod_config['width'] = $image_size->image_size_width;
                    $mod_config['height'] = $image_size->image_size_height;

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

                    if ( ! $this->image_lib->resize())
                    {
                        echo $this->image_lib->display_errors();exit;
                    }

                    $this->image_lib->clear();
                }
  • 写回答

1条回答 默认 最新

  • duanke8011 2019-05-21 06:19
    关注

    Demo from Codeigniter Doc with some changes because it is not working in my case:

    $this->load->library('image_lib');
    
    $config['image_library'] = 'gd2';
    $config['source_image'] = '/path/to/image/mypic.jpg';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 75;
    $config['height'] = 50;
    
    $this->image_lib->initialize($config);
    
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
    } 
    
    $this->image_lib->clear();
    

    Explanation:

    The above code tells the image_resize function to look for an image called mypic.jpg located in the source_image folder, then create a thumbnail that is 75 X 50 pixels using the GD2 image_library. Since the maintain_ratio option is enabled, the thumb will be as close to the target width and height as possible while preserving the original aspect ratio. The thumbnail will be called mypic_thumb.jpg and located at the same level as source_image.

    评论

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件