0

I’ve been reading the docs and trying everything to make thumbs out of uploaded images but I can’t seem to find the problem.

Images are uploaded and saved correctly but thumbs are not, it fails with no error output. This is the code I’m using:

$data = $this->upload->data();

$config_image['image_library'] = 'gd';
$config_image['source_image'] = $data['full_path'];
$config_image['new_image'] = 'uploads/thumbs/';
$config_image['create_thumb'] = TRUE;
$config_image['maintain_ratio'] = TRUE;
$config_image['width'] = 750;
$this->load->library('image_lib', $config_image);

if ( !$this->image_lib->resize())
{
    $this->session->set_flashdata('message',  $this->image_lib->display_errors());
} 

Also, I want to resize images to fit max-width=750, but maintain the ratio. Is what I’m doing correct to achieve that? Thanks!

5 Answers 5

2

I know this is a little too late, but I recently had the same issue and solve it by initializing the class.

The CodeIgniter example does not work, you have to load the class first:

$this->load->library('image_lib');

Then after setting the config you need, then you initialize the class like so:

$this->image_lib->initialize($config);

This worked for me right away.

I'm posting this in case anyone else is having the same issue, so they solve it with CodeIgniter and not another library.

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe both, width AND height must be specified? Just try it with a fixed height (and do aspect ratio aware scaling in a second step).

For maintaining the ratio, its simple, first compute the aspect ratio of the image, then compute the target height:

$target_width = 750;
$image_aspect_ratio = $image_width / $image_height;
$target_height = $target_width / $image_aspect_ratio;

You can deduce this from simple math: r = w/h. So, w=r*h (=the target width, if you have a fixed height) and h = w/r (=the target height, if you have a fixed width).

Comments

1

You definitely have to use GD2.

CI's image manipulation class is a bit temperamental sometimes. If you can not get things to work, check out timthumb. It's a small 1 file php script that resizes images on the fly and uses a caching system. You just pass the required paramters through the src attribute of your image tag. Very easy, works very well and much less of a headache than CI's image manipulation class.

2 Comments

Yeah, I know it and I'm definitely considering it since this is not working.
Well, I'm marking this as correct, since I ended up with the allmighty timthumb :)
0

remove $config_image['new_image'] = 'uploads/thumbs/'; and change $config['image_library'] = 'gd'; to $config['image_library'] = 'gd2';

Also make sure the $data array contains the full_path.

Comments

0

Simple question, are the file permissions correct? Another tip would be to set CIs error logging to the highest leven and see if it outputs anything.

1 Comment

Well, I think so, but I'm not 100% sure. I'll check on that thoroughly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.