resizing multiple images

edited June 2012 in Modules
I have 5 image upload fields. I am trying to resize all 5 images, at the moment when the script runs it will only resize one of the 5. Heres the code

function on_after_post($values)
{
$CI =& get_instance();
$CI->load->library('image_lib');

// create the thumbnail if an image is uploaded
if (!empty($CI->upload))
{
$data = $CI->upload->data();
if (!empty($data['full_path']))
{
$thumb_img300 = assets_server_path('prod/300/'.$this->thumb_name($data['file_name']), 'images');

// create thumb 300 height
$config = array();
$config['source_image'] = $data['full_path'];
$config['create_thumb'] = FALSE;
$config['new_image'] = $thumb_img300;
$config['width'] = 200;
$config['height'] = 300;
$config['master_dim'] = 'auto';
$config['maintain_ratio'] = TRUE;
//$CI->image_lib->clear();
$CI->image_lib->initialize($config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}

}
return $values;
}

Comments

  • edited 12:43PM
    Is that the complete code?

    upload->data() gets you an array of information for a file, from the docs: This is a helper function that returns an array containing all of the data related to the file you uploaded.

    So it's per file, hence only saving one.
  • edited 12:43PM
    So would you have to foreach the upload data? I have 5 upload fields
  • edited June 2012
    If I use a multifile class on my image upload field, how can I access the path for each uploaded image inside my on_after_post hook for processing (using a loop, I guess)?
  • edited 12:43PM
    There is a property set on the model called "upload_data" which contains an array of the uploaded data that you should be able to access from within your on_after_post hook
Sign In or Register to comment.