Welcome Guest, Not a member yet? Register   Sign In
Image manipulation class documentation
#1

[eluser]SPeed_FANat1c[/eluser]
Hi,

I made a function

Code:
function image_resize($image_name)
    {
        
        $this->load->library('image_lib');
        $config['image_library'] = 'gd2';

        $config['source_image']    = './uploads/info_pages/'.$image_name;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 75;
        $config['height']    = 50;
        
        $this->load->library('image_lib', $config);
        //$this->image_lib->initialize($config);
        
        if ( ! $this->image_lib->resize())
        {
            return $this->image_lib->display_errors();
        }
        else return 'ok';
    }

And you see there is one line commenter - $this->image_lib->initialize($config);
When this line is commended, resizing does not work.

But if we look at the documentation, example is such:

Code:
$config['image_library'] = 'gd2';
$config['source_image']    = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']     = 75;
$config['height']    = 50;

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

$this->image_lib->resize();

So there is no initialization line. This is a mistake I guess. I am lucky that I had old examples and quickly found, but for those who are new to CI it is hard to find why it does not work.
#2

[eluser]Atharva[/eluser]
This is not a mistake
Code:
$this->load->library('image_lib', $config);

The second parameter is optional and if passed, automatically initializes the library with parameters, so that there is not need of separate initialize function.
#3

[eluser]SPeed_FANat1c[/eluser]
But as you can see in my code I use that second parameter, why it does not work for me?
#4

[eluser]Atharva[/eluser]
It is not working for you coz you are loading image library twice. Comment out the first line in function, that is
Code:
$this->load->library('image_lib');
and just use
Code:
$this->load->library('image_lib', $config);
after you set options in config array. You will also not need the initialize function in this case.
#5

[eluser]SPeed_FANat1c[/eluser]
Oh, stupid mistake that was Big Grin Thanks Smile




Theme © iAndrew 2016 - Forum software by © MyBB