Welcome Guest, Not a member yet? Register   Sign In
Preventing resize of smaller images
#4

[eluser]Michael Wales[/eluser]
I usually find that you don't actually need to define your resize by both height and width. Usually you simply want to say, "I don't want this any wider than 800px" or "No taller than 400px"

If this is the case, just define that one "must have" size and the image library will take care of the rest. The following example assumes the image was uploaded with the File Upload class:

Code:
$uploaded_img = $this->upload->data();

$config['source_image'] = $uploaded_img['full_path'];
$config['width'] = 800;
$this->load->library('image_lib', $config);

if ($uploaded_img['image_width'] > $config['width']) {
  $this->image_lib->resize();
}

I don't have an environment to test in - as I said, I believe this would work. If not, it's really simple to dynamically generate the height (just a basic proportion from elementary school math):
Code:
$config['height'] = ($uploaded_img['image_height'] * $config['width']) / $uploaded_img['image_width'];


Messages In This Thread
Preventing resize of smaller images - by El Forum - 10-24-2007, 12:28 PM
Preventing resize of smaller images - by El Forum - 12-29-2008, 09:22 AM
Preventing resize of smaller images - by El Forum - 12-29-2008, 10:47 AM
Preventing resize of smaller images - by El Forum - 12-29-2008, 11:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB