• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
image_lib autoload'ing

#1
[eluser]Ossama Khayat[/eluser]
Isn't the image_lib library just like any other library, that it can be loaded using autoload.php?
I'm writing a small app and using this function, in my controller:
Code:
<?php
function _image_url($field)
{
    $this->load->library('image_lib');
    if (preg_match('/jpg|png/', $field) && file_exists(FCPATH.'/images/'.$field))
    {
        $file_url = base_url().'images/';
        $img_lib_config = array(
            'image_library' => 'gd2',
            'source_image' => FCPATH.'/images/'.$field,
            'create_thumb' => TRUE,
            'maintain_ratio' => TRUE,
            'width' => 100,
            'height' => 200
        );
        $this->image_lib->initialize($img_lib_config);
        if ($this->image_lib->resize() === TRUE)
        {
            list($name, $ext) = explode('.', $field);
            $new_name = $name.'_thumb.'.$ext;
            $this->image_lib->clear();
            return '<img src="'.$file_url.$new_name.'" width="100"/>';
        }
        return '<img src="'.$file_url.$field.'" width="100"/>';
    }
    return $field;
}
?&gt;
which will basically read the image name field, and create thumb. It works fine.
Now, I wanted to load the image_lib library automatically instead of inside this function.
If I do that it doesn't work.
Any idea?

#2
[eluser]Ossama Khayat[/eluser]
Note that even if I load the library within the function, it wouldn't work if I load it within autoload.php


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.