views:

68

answers:

2

Hey :) I want to resize an image when I address it in a form(save to database). I dont think it will be a problem [pointing to the image etc, however the space I am going display the thumb in is 228 x 228. I know I can maintain the ratio and determine the size in the controller, yet how is it done on images that are frequently different sizes?

Is the best way to address this is to put pre-calculated values(make my own ratio) in my form so that the controller can use those values to determine max height and width? See code.

$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']     = 75; // use $this->input->post('width') instead??
$config['height']   = 50;  // use $this->input->post('height')

Or is there a way to tell the function no bigger than 228 and no wider than 228?

Thanks

+1  A: 

getImageSize()

I think you'd have to throw some logic in your controller to handle this. Using the function above you can test the height/width of the uploaded image and resize if necessary.

mdonovan2010
I understand, most of the images will be much larger. I think you are saying test for the correct ratio?
Brad
+1  A: 

I am not sure what you want exactly, but by using the following settings you can make sure either the width or the height of the image is 228px. If width > height, width will be 228px. And vice versa.

$config['maintain_ratio'] = TRUE;
$config['master_dim'] = 'auto' // auto is default, so you can leave this out
$config['width'] = 228;
$config['height'] = 228;

master_dim

Specifies what to use as the master axis when resizing or creating thumbs. For example, let's say you want to resize an image to 100 X 75 pixels. If the source image size does not allow perfect resizing to those dimensions, this setting determines which axis should be used as the hard value. "auto" sets the axis automatically based on whether the image is taller then wider, or vice versa.

If this is not what you mean, please add a bit more explanation.

captaintokyo
I think thats exactly what I want. As long as the width and height isn't set in stone as the size "having to be 228 x 228'. I see what you are saying and I beleive that will work. Thank you much
Brad