【问题标题】:I am unable to resize my image in codeigniter我无法在 codeigniter 中调整图像大小
【发布时间】:2017-07-19 10:17:17
【问题描述】:
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'jpg|jpeg|png|gif';
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 100;
    $config['height'] = 150;
    $config['file_name'] = $_FILES['image']['name'];
    $this->load->library('image_lib', $config);
    $this->image_lib->resize();
    $this->image_lib->initialize($config); 
    $this->load->library('upload',$config);
    $this->upload->initialize($config);

我无法调整图像大小...请告诉我我的错误

【问题讨论】:

标签: php codeigniter


【解决方案1】:

根据@jigar Shah 的评论,您必须先初始化上传库,然后再调整大小

            $this->load->library('upload');
            $config['upload_path'] = './uploads';
            $config['allowed_types'] ='csv|xls|xlsx';
            $config['max_size'] = 1024;  //in KB
            $config['overwrite'] = TRUE;
            $config['encrypt_name'] = TRUE;
            $config['max_filename'] = 25;
            $this->upload->initialize($config);
        if (!$this->upload->do_upload('image_name')) {
                //if file upload failed then catch the errors
                $this->handle_error($this->upload->display_errors());
                $is_file_error = TRUE;
            } else {
                 //store the file info
                $image_data = $this->upload->data();
                $config['image_library'] = 'gd2';
                $config['source_image'] = $image_data['full_path']; //get original image
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 150;
                $config['height'] = 100;
                $this->load->library('image_lib', $config);
                if (!$this->image_lib->resize()) {
                    $this->handle_error($this->image_lib->display_errors());
                }
            }

更多参考请visit

【讨论】:

    猜你喜欢
    • 2018-06-17
    • 2011-06-28
    • 2018-02-14
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多