Codeigniter图像没有裁剪

时间:2011-10-03 12:28:27

标签: codeigniter

我尝试使用以下代码在codeigniter中裁剪图像,但它不起作用。我可能会错过微小的事情。辅助器已加载,图像也存在 代码是

 public function cropAndSave(){
                    $config['image_library'] = 'gd2';
                    $config['allowed_types'] = 'gif|jpg|png';
                    $config['source_image'] = './img-lab/xxx.jpg';
                    $config['create_thumb'] = true;
                    $config['maintain_ratio'] = false;
                    $config['width'] = 150;
                    $config['height'] = 190;
                    $config['new_image'] = "thumb_shahid.jpg";
                    $this->load->library('image_lib', $config);
                    $this->image_lib->resize();
                    echo '
                    <script>
                         window.parent.location="'.  base_url().'"
                    </script>
                    ';
}

1 个答案:

答案 0 :(得分:1)

调用initialize()函数而不是load(),因为您的图片库已加载

 public function cropAndSave(){
                        $config['image_library'] = 'gd2';
                        $config['allowed_types'] = 'gif|jpg|png';
                        $config['source_image'] = './img-lab/xxx.jpg';
                        $config['create_thumb'] = true;
                        $config['maintain_ratio'] = false;
                        $config['width'] = 150;
                        $config['height'] = 190;
                        $config['new_image'] = "thumb_shahid.jpg";
                        $this->image_lib->initialize($config);
                        $this->image_lib->resize();
                        echo '
                        <script>
                             window.parent.location="'.  base_url().'"
                        </script>
                        ';
    }