⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

What do you do if you need to resize thumb and other pics?



alvarito
  • profile picture
  • Member

Posted 10 October 2012 - 15:36 PM

The thumb has say 100 x 100, the pics have all say, 600 x 400.

How can you put all that in one callback after upload function?

Note that you will have different upload buttons, one for each pic (as each goes to a column in the table of the database)

This does not work. Using two different callback after upload functions, it will endup resizing the thumb to the size of the pic. If I put all the commands in one function, the result is the opposite. the pic is resized to the size of the thumb




$crud->set_field_upload('thumb_a','assets/uploads/thumbs');
$crud->callback_after_upload(array($this,'resizethumb'));


$crud->set_field_upload('pic1','assets/uploads/pics');
$crud->callback_after_upload(array($this,'resizepic'));

$output = $crud->render();

$this->_example_output($output);
}

function resizethumb($uploader_response,$field_info, $files_to_upload)
{


//Is only one file uploaded so it ok to use it with $uploader_response[0].
$thumb_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
$this->image_moo->load($thumb_uploaded)->resize(100,100)->save($thumb_uploaded,true);

return true;
}



function resizepic($uploader_response,$field_info, $files_to_upload)
{
$pic_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
$this->image_moo->load($pic_uploaded)->resize(630,400)->save($pic_uploaded,true);

return true;

}