开发者

Codeigniter image is not cropping

I tried the following code to crop an image in codeigniter but it did not work. Might be I am missing minute thing. Helper is loaded and the image is also exists The code is

 public function cropAndSave(){
                    $config['image_library'] = 'gd2';
                    $config['allowed_types'] = 'gif|jpg|png';
                    开发者_StackOverflow社区$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>
                    ';
}


Call the initialize() function instead of load() because your image library already loaded

 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>
                        ';
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜