【问题标题】:Codeigniter Resize function not workingCodeigniter 调整大小功能不起作用
【发布时间】:2014-05-23 11:05:27
【问题描述】:

嗨朋友们,我正在尝试使用 codeigniters resize image_lib .. 我无法使用这个来调整图像的大小。请帮我解决这个问题

错误:

使用 gd: 图片路径不正确。您的服务器不支持处理此类图片所需的 GD 功能。

使用 ImageMagick: 图片的路径不正确。图片库的路径不正确。请在您的图片偏好中设置正确的路径。

代码:

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

            $config['upload_path'] = $path;

            $config['file_name']  = $file_name;

            $config['allowed_types'] = 'jpg|png'; 

            $config['overwrite'] = false;

            $this->upload->initialize($config);

            if ( ! $this->upload->do_upload())
            {    
                    return false;
            }    

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

                    $resize['image_library'] = 'gd2';
                    $resize['source_image'] = $path.$file_name;    

                    $resize['maintain_ratio'] = FALSE;
                    $resize['width'] = 40; 
                    $resize['height'] = 40; 
                    $resize['quality'] = 100;

          //           print_r($path.$file_name);
         // Here the path of the image is assets/Data/adv_images/2/2-537f2a3651300
        //  which is absolutely right  also tried base_url().$path.$file_name

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

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

【问题讨论】:

  • 你可以试试ImageMagick而不是GD2并发布结果。
  • @karanthakkar 我已经编辑了帖子并将 Imagemagick 的结果添加到帖子中,尽管图像的路径是正确的
  • 你能告诉我们 $path 变量吗
  • $path = 'assets/Data/adv_images/2/' 和 $file_name = '2-537f2a3651300' 。上传时是否需要更改文件权限?
  • 应该是$path = './assets/Data/adv_images/2/'@HackerRocker

标签: php codeigniter codeigniter-2


【解决方案1】:

尝试通过这种方式设置路径:

$resize['source_image'] = $this->upload->data()['full_path'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 2014-08-29
    • 2023-03-31
    • 2016-12-31
    • 2011-02-05
    • 1970-01-01
    • 2015-10-22
    相关资源
    最近更新 更多