Welcome Guest, Not a member yet? Register   Sign In
resize AND create thumb?
#1

[eluser]M4rc0[/eluser]
So I want to resize an image and also create a thumb of it

The thing is that if I use:
Code:
$config['create_thumb'] = TRUE;


I will only get mypic_thumb.jpg on the folder

and not:
- mypic.jpg
- mypic_thumb.jpg

which is what I need.

What do you think is the correct way to get this?

I was thinking of this:
Code:
function do_image() {        
        
                $fullPath = "path/mypic.jpg";
        $config['new_image'] = "path/mypic.jpg";
        $config['maintain_ratio'] = TRUE;        
        $config['source_image'] = "path/abc.jpg";
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 600;
        $config['height'] = 400;

        if ( ! $this->image_lib->resize()){
            echo $this->image_lib->display_errors();
        }else {$this->do_thumb($fullPath);}
    }    

    function do_thumb($image) {

        $config['maintain_ratio'] = TRUE;        
        $config['source_image'] = $image;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 150;
        $config['height'] = 150;
                $config['create_thumb'] = TRUE;        
        if ( ! $this->image_lib->resize()){
            echo $this->image_lib->display_errors();
        }else { return true;}
    }

But note the image_lib beeing called twice..this is not DRY :-S

should I create the thumb on the fly instead?
#2

[eluser]siubie[/eluser]
i think the problem is in calling image_lib twice
try autoload the image_lib and use
$this->image_lib->initialize($config);

or maybe this topic will help :
http://ellislab.com/forums/viewthread/105844/

~siubie~
#3

[eluser]M4rc0[/eluser]
Hi siubie! thanks for the reply!

I'm sure the code above will work, but I wanted something more DRY

and it's not about the image_lib beeing called twice, but using it twice..you know what I mean?

isn't there a way of creating a thumb inside the do_image function, for example? how would you do this?
#4

[eluser]Vicente Russo[/eluser]
You may create on the fly, OR implement your own resize-and-thumb-in-one-step. The actual CI's imagelib doesn't support 2 operations..
#5

[eluser]M4rc0[/eluser]
Thanks for the replies.

I believe on the fly is the best option.

Thanks.
#6

[eluser]stef25[/eluser]
im also trying to resize an image AND create thumbnail. what do you guys mean by creating a thumn "on the fly", how is this done?




Theme © iAndrew 2016 - Forum software by © MyBB