Saad Shaikh
Saad Shaikh

Reputation: 83

How do I resize an image in CodeIgniter?

How do I resize an image in CodeIgniter?

This is my code...

{
        $this->load->library('image_lib');
        // Set your config up
        $config['image_library']    = "gd2";      
        $config['source_image']     = './uploads/header_images/' .$filename;
        $config['new_image']        = './uploads/header_images/thumbnail/'.$filename;       
        $config['create_thumb']     = TRUE;      
        $config['maintain_ratio']   = false;      
        $config['width'] = "50";      
        $config['height'] = "50";
        // $config['quality']  = '100';
        $this->image_lib->initialize($config);
        // Do your manipulation
        $this->image_lib->resize();
        if(!$this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        } 
        // $this->image_lib->clear();     
    }

my image is been streched i want image to maintain aspect ratio

Upvotes: 1

Views: 66

Answers (1)

438sunil
438sunil

Reputation: 188

Set this value to true:

$config['maintain_ratio'] = true; 

Upvotes: 1

Related Questions