[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;
}
?>
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?