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>
';
}
精彩评论