I am trying to upload multiple images, re-size those images, then create thumbnails for the images via codeigniter.
$config['upload_path'] = '---path---';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = FALSE;
$this->load->library('upload');
$files = $_FILES;
$cpt = count($_FILES['files']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['files']['name']= $files['files']['name'][$i];
$_FILES['files']['type']= $files['files']['type'][$i];
$_FILES['files']['tmp_name']= $files['files']['tmp_name'][$i];
$_FILES['files']['error']= $files['files']['error'][$i];
$_FILES['files']['size']= $files['files']['size'][$i];
$this->upload->initialize($config);
$this->upload->do_upload('files');
$tmp = $this->upload->data();
$this->load->library('image_lib');
//Thumbnail configs
$config_t['source_image'] = '---path---' . $tmp['file_name'];
$config_t['new_image'] = '--path to thumbnail ---' . $tmp['file_name'];
$config_t['create_thumb'] = TRUE;
$config_t['maintain_ratio'] = TRUE;
$config_t['width'] = 110;
$config_t['height'] = 110;
//end of configs
$this->load->library('image_lib', $config_t);
$this->image_lib->initialize($config_t);
if(!$this->image_lib->resize())
echo "Failed." . $this->image_lib->display_errors();
//Resize Configs
$config_r['source_image'] = '----path----' . $tmp['file_name'];
$config_r['maintain_ratio'] = TRUE;
$config_r['width'] = 800;
$config_r['height'] = 800;
$config_r['quality'] = 100;
//end of configs
$this->load->library('image_lib', $config_r);
$this->image_lib->initialize($config_r);
if(!$this->image_lib->resize())
echo "Failed." . $this->image_lib->display_errors();
}
The image uploading works fine, every image gets uploaded, the problem is the image manipulation:
No errors are displayed, however the images aren't being being resized to 800x800 px or 100x100
EDIT::
The images are getting copied into the thumbnail folder, they just had the _thumb rename. However, the thumbnail images are being re-sized to "something" by 800px, EX:
1289px by 800px
they should be 100px by 100px, the original image is still not being re-sized
EDIT::
If I remove the re-size configs:
//Resize Configs
$config_r['source_image'] = '----path----' . $tmp['file_name'];
$config_r['maintain_ratio'] = TRUE;
$config_r['width'] = 800;
$config_r['height'] = 800;
$config_r['quality'] = 100;
//end of configs
$this->load->library('image_lib', $config_r);
$this->image_lib->initialize($config_r);
if(!$this->image_lib->resize())
echo "Failed." . $this->image_lib->display_errors();
the thumbnail re-size/upload works perfectly, just need to figure a way to do both
$config['upload_path'] = '---path---';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = FALSE;
$this->load->library('upload');
$files = $_FILES;
$cpt = count($_FILES['files']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['files']['name']= $files['files']['name'][$i];
$_FILES['files']['type']= $files['files']['type'][$i];
$_FILES['files']['tmp_name']= $files['files']['tmp_name'][$i];
$_FILES['files']['error']= $files['files']['error'][$i];
$_FILES['files']['size']= $files['files']['size'][$i];
$this->upload->initialize($config);
$this->upload->do_upload('files');
$tmp = $this->upload->data();
$this->load->library('image_lib');
//Thumbnail configs
$config_t['source_image'] = '---path---' . $tmp['file_name'];
$config_t['new_image'] = '--path to thumbnail ---' . $tmp['file_name'];
$config_t['create_thumb'] = FALSE;///change this
$config_t['maintain_ratio'] = TRUE;
$config_t['width'] = 110;
$config_t['height'] = 110;
//end of configs
$this->load->library('image_lib', $config_t);
$this->image_lib->initialize($config_t);
if(!$this->image_lib->resize())
echo "Failed." . $this->image_lib->display_errors();
//Resize Configs
$config_r['source_image'] = '----path----' . $tmp['file_name'];
$config_r['maintain_ratio'] = TRUE;
$config_t['create_thumb'] = FALSE;///add this
$config_r['width'] = 800;
$config_r['height'] = 800;
$config_r['quality'] = 100;
//end of configs
$this->load->library('image_lib', $config_r);
$this->image_lib->initialize($config_r);
if(!$this->image_lib->resize())
echo "Failed." . $this->image_lib->display_errors();
}
Have you tried clearing the cache after resizing it again?
$this->image_lib->resize()
$this->image_lib->clear();
just load the library once and use the initialize.
then clear it after every resize
$config_t['source_image'] = '---path---' . $tmp['file_name'];
$config_t['new_image'] = '--path to thumbnail ---' . $tmp['file_name'];
$config_t['create_thumb'] = TRUE;
$config_t['maintain_ratio'] = TRUE;
$config_t['width'] = 110;
$config_t['height'] = 110;
$config_r['source_image'] = '----path----' . $tmp['file_name'];
$config_r['maintain_ratio'] = TRUE;
$config_r['width'] = 800;
$config_r['height'] = 800;
$config_r['quality'] = 100;
//end of configs
//load library once
$this->load->library('image_lib');
//use first config
$this->image_lib->initialize($config_t);
//run resize
if(!$this->image_lib->resize())
{
echo "Failed." . $this->image_lib->display_errors();
}
//clear
$this->image_lib->clear();
//initialize second config
$this->image_lib->initialize($config_r);
//run resize
if(!$this->image_lib->resize())
{
echo "Failed." . $this->image_lib->display_errors();
}
//clear
$this->image_lib->clear();