CodeIgniter调整大小上传的图像不起作用

时间:2013-04-02 14:44:32

标签: php codeigniter

我想创建上传图片的缩略图,然后调整上传图片的大小。 这是我的代码:

$data = array('upload_data' => $this->upload->data());
            $upload_data = $data['upload_data'];


            //Create image thumbnail
            $config['image_library'] = 'gd2';
            $config['source_image'] = $upload_data['full_path'];
            $config['create_thumb'] = TRUE;
            $config['overwrite'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 150;
            $config['height'] = 150;

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

            $this->image_lib->resize();

            //Resize original image for space saving purposes
            if ($upload_data['image_width'] > 850 || $upload_data['image_height'] > 850) {

                $config['image_library'] = 'gd2';
                $config['source_image'] = $upload_data['full_path'];
                $config['maintain_ratio'] = TRUE;
                $config['create_thumb'] = FALSE;
                $config['overwrite'] = TRUE;
                $config['width'] = 850;
                $config['height'] = 850;

                $this->load->library('image_lib', $config);
                $this->image_lib->resize();
            }

缩略图创建得很好,但原始图像的大小调整不起作用。我在这里缺少什么?

编辑:我尝试添加以下行:

$this->image_lib->clear();
两个图像处理之间的

1 个答案:

答案 0 :(得分:2)

原来我需要重新初始化$ config,如下所示:

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