调整图像大小不适用于codigniter

时间:2018-03-20 18:51:35

标签: php codeigniter

它没有显示任何错误,什么都不做,我无法理解它的错误!

    public function resize($path,$filename) {
            $config['image_library']   = 'gd2';
            $config['source_image']    = $path;
            $config['create_thumb']    = TRUE;
            $config['maintain_ratio']  = TRUE;
            $config['width']           = 75;
            $config['height']          = 50;
            $config['new_image']       = './img/uploads/users/'.$filename . '.jpg';
            $this->load->library('image_lib');
            $this->image_lib->initialize($config);
            $this->image_lib->clear();
            if(!$this->image_lib->resize()) {
                echo $this->image_lib->display_errors();
            }
}

1 个答案:

答案 0 :(得分:0)

问题是你在调整大小方法之前调用clear方法,它清除所有设置尝试这个方法,我已经测试了相同的目录结构它工作正常

public function resize($path, $filename)
    {
        $config['image_library'] = 'gd2';
        $config['source_image'] = $path;
        $config['create_thumb'] = true;
        $config['maintain_ratio'] = true;
        $config['width'] = 75;
        $config['height'] = 50;
        $config['new_image'] = './img/uploads/users/' . $filename . '.jpg';
        $this->load->library('image_lib');
        $this->image_lib->initialize($config);
        // $this->image_lib->clear();
        if (!$this->image_lib->resize()) {
            echo $this->image_lib->display_errors();
        }
    }