views:

38

answers:

4

Hi all, 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!

A: 

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.

Kieran Allen
Sorry, this didn't work.
ign
Do you get any error messages?
stef
No, fails silently.
ign
+1  A: 

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).

frunsi
+1  A: 

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.

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

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.

Yorick Peterse
Well, I _think_ so, but I'm not 100% sure. I'll check on that thoroughly.
ign