• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Am I using the image lib library properly?

Compared to other parts of CI, this seems to be a terrible amount of code to do what I am trying to do.

1 - Measure image, determine whether width or height or is larger.
2 - Resize image by smallest attribute
3 - Crop image

// Make Thumb
$config['image_library'] = 'gd2';
$config['source_image']    = getcwd().'/uploads/' . $upload['file_name'];
$config['new_image']    = getcwd().'/uploads/_40thumb_' . $upload['file_name'];
$config['maintain_ratio'] = TRUE;
if ($upload['image_width'] > $upload['image_height']) {
    $width = (40 / $upload['image_height']) * $upload['image_width'];
    $height = 40;
} else {
    $width = (40 / $upload['image_width']) * $upload['image_height'];
    $height = 40;
$config['width'] = $width;
$config['height'] = $height;
$this->load->library('image_lib', $config);
// Crop
$config['source_image'] = getcwd().'/uploads/_40thumb_' . $upload['file_name'];
$config['width'] = 40;
$config['height'] = 40;
$config['maintain_ratio'] = FALSE;

When it comes to image manipulation just a simple upload and re-size can become a large block of code.

In one of my apps i have over 50 lines of code so i can upload, optimize(re-size, crop, quality), store in a database and save it in its own folder.

That's just to get the image uploaded, to manipulate the image over 100 lines of code and more than 6 functions this is to focus, rotate, re-crop, re-size, watermark, update the database with all this parameter and finally output to the browser.

But writing this much code helps minimize different functions kind of like a library or model you write a lot of code so you can then use small pieces to manipulate data/files/images.

In this case your benefit is that the image is uploaded and re-size and all a user had to do is click upload.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.