[eluser]apobukay[/eluser]
I'm having a bug when I resizing multiple images some images would not resize correctly and some would not resize, the resize works perfectly when i just resize one image. I want to resize multiple images . how to do that?
my code flow, first upload the images then resize it.
Please help me.. thank you in advance.
here is my code:
note: I'm using multiple upload Library and it works perfectly.
Code:
function upload_process()
{
$config['upload_path'] = './uploads/'; // server directory
$config['allowed_types'] = 'gif|jpg|jpeg|bmp|png'; // by extension, will check for whether it is an image
$config['max_size'] = '2000'; // in kb
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$this->load->library('multi_upload');
$files = $this->multi_upload->go_upload('userfile');
if(!$files)
{
echo $files;
echo $this->multi_upload->display_errors();
echo 'error upload';
}
else
{
$upload_data =$files;
$i = 0;
$num = 0;
foreach ($upload_data as $file)
{
$photoID = random_string('alnum', 5);
$photo_orig = $file['name'];
$photo_view_crop = $file['name'];
$photo_view_resize = $file['name'];
$photo_thumbnail = $file['raw_name'] . '_thumb' . $file['ext'];
$height = $file['height'] ;
$width = $file['width'];
if($width <=150)
{
$photo_orig = $file['name'];
$photo_thumbnail = $file['raw_name'] . '_thumb' . $file['ext'];
$img_path = 'uploads/'.$photo_orig;
$img_new ='uploads/'.$photo_thumbnail;
$config_t['image_library'] = 'gd2';
$config_t['new_image'] = $img_new;
$config_t['source_image'] = $img_path;
//$config['create_thumb'] = FALSE;
$config_t['maintain_ratio'] = TRUE;
$config_t['width'] = 150;
$config_t['height'] = 150;
$this->image_lib->initialize($config_t);
$this->image_lib->resize();
$this->image_lib->clear();
}
else{
$photo_orig1 = $file['name'];
$photo_orig = $file['name'];
$photo_thumbnail = $file['raw_name'] . '_thumb' . $file['ext'];
$image_new = $file['raw_name'];
$config_r['image_library'] = 'gd2';
$config_r['source_image'] = 'uploads/'. $image;
$config_r['create_thumb'] = TRUE;
$config_r['maintain_ratio'] = TRUE;
$config_r['width'] = 150;
$config_r['height'] = 150;
$this->image_lib->initialize($config_r);
$this->image_lib->resize();
$this->image_lib->clear();
$img_path = 'uploads/'.$photo_orig ;
$img_new ='uploads/'.$photo_orig ;
$config_y['image_library'] = 'gd2';
$config_y['source_image'] = $img_path;
$config_y['create_thumb'] = FALSE;
$config_y['maintain_ratio'] = TRUE;
$config_y['width'] = 650;
$config_y['height'] = 650;
$this->image_lib->initialize($config_y);
$this->image_lib->resize();
$this->image_lib->clear();
}
}
}