Welcome Guest, Not a member yet? Register   Sign In
Whats the best way to use this? model, extend library or other?
#1

[eluser]bugboy[/eluser]
Hello all

I have a quick question.

I have this code which i use a lot to help me create the image size's i need.

I use this a lot as it allows me to have a loop and to create images sizes when uploading multiple images.

At the minute i have placed it in a model and it works just fine and keeps my code smaller and neater. But i'm wondering is this the best way or am i right in thinking i could extend the image_lib libray to do this?

I just want to get my coding practice up to scratch.

Code:
function resizeImage($filename, $folder, $width, $height, $thumb=FALSE){
        
        $config['source_image'] = $folder.$filename;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = $width;
        $config['height'] = $height;
        $config['master_dim'] = 'width';
        
        // create a thumb
        if($thumb == TRUE){
            $config['new_image'] = $folder.'thumb_'.$filename;
        }
        
        $this->image_lib->initialize($config);
        
        if ( ! $this->image_lib->resize())
        {
            return $this->image_lib->display_errors();
        }
    
    }

Any advice would be most appreciated.

Smile
#2

[eluser]nirbhab[/eluser]
There is one more way i would prefer to do so, is extending the image_lib class, and upgrade the class with upper mentioned method. so that my code becomes reusable, and help full to others too, due to lack of time, i am not able to add some sample code but, you can surely refer to extending library from CI user guide.
#3

[eluser]bugboy[/eluser]
i thought that extending the image class would the be the answer.

Cheers

would it be something like this


in fact i know this isn't right. but am i on the right track?
Code:
class MY_Image_lib extends CI_Image_lib {

    function MY_Image_lib()
    {
        parent::CI_Image_lib();
    }


    function resizeImage($filename, $folder, $width, $height, $thumb=FALSE){
        
        $config['source_image'] = $folder.$filename;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = $width;
        $config['height'] = $height;
        $config['master_dim'] = 'width';
        
        // create a thumb
        if($thumb == TRUE){
            $config['new_image'] = $folder.'thumb_'.$filename;
        }
        
        $this->image_lib->initialize($config);
        
        if ( ! $this->image_lib->resize())
        {
            return $this->image_lib->display_errors();
        }
    
    }


}




Theme © iAndrew 2016 - Forum software by © MyBB