Welcome Guest, Not a member yet? Register   Sign In
CI Image Manipulation Help
#1

[eluser]dennismonsewicz[/eluser]
Here is my code inside my controller:

Code:
function resize_image($height, $width, $ratio) {
        $config['source_image'] = '../uploads/profile_image/l_228efa6889bb4eba8572b7cce1344ffc1.jpg';
        $config['maintain_ratio'] = $ratio;
        $config['dynamic_output'] = TRUE;
        $config['width'] = $width;
        $config['height'] = $height;

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

Calling this function in view:

Code:
<img src="&lt;?=base_url() . 'profile/resize_image/350/400/1';?&gt;" />

I cannot get the above to work... I was directed to a blog here: http://www.noquieroprogramar.com/generar...deigniter/

I followed their example to the tee and can't get anything going... what could I be doing wrong?
#2

[eluser]JasonS[/eluser]
You do realise that the image library actually resizes the image file right? You do not want to put this into html.

You want to resize the image before you render the page code.

To get the file name I set the following config variable.

Code:
$config['new_image'] = '/path/to/new_image.jpg';

Then I return $config['new_image']
#3

[eluser]dennismonsewicz[/eluser]
but according to your code you are creating a new image... I just want to resize my image on the fly
#4

[eluser]nzmike[/eluser]
Resizing an image is a really expensive operation. Does it really need to be done on the fly?
#5

[eluser]dennismonsewicz[/eluser]
it would be nice... but if not then how would i incorporate my original code to do a thumbnail?
#6

[eluser]dennismonsewicz[/eluser]
It seems like the CI is failing with its documentation on this particular library...

Here is my updated code and its NOT working:

Code:
$this->load->library('image_lib');
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = $path;
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 400;
            $config['new_image'] = '/uploads/profile_images/thumbs/thumb_' . $origName;
            
            $this->image_lib->initialize($config);
            $this->image_lib->resize();

This is in a function that is uploading an image but I need it to create a thumbnail and ITS NOT!
#7

[eluser]Aken[/eluser]
Nothing wrong with CI's documentation.

Looking at the example's original code, there should be nothing wrong with that. The only things that could affect it are the lack of an image library specified, and possible wrong settings for the source_image location.

Look up your phpinfo() to see what image library is installed. GD2 is the most typical and easy to use. Specify whichever one your server supports. Also change your image paths to be a full absolute path (not a normal URL, but the /path/to/public_html/uploads/etc). That way there's no guessing what the relative path should be to the image.

You also do not need the new_image config item when dynamically outputting an image, since that's just for creating copies.




Theme © iAndrew 2016 - Forum software by © MyBB