Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 3 Multiple Thumbnails
#1

(This post was last modified: 11-23-2022, 04:56 AM by deepakaryan.)

I want to create Multiple Thumbnails from single upload. I am using this code 
 
PHP Code:
function do_upload(){
    $config['upload_path'] = './public/assets/img_content/'//path folder
      $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
      $config['encrypt_name'] = FALSE;

      $this->upload->initialize($config);

    if(!empty($_FILES['filefoto']['name'])){
              if ($this->upload->do_upload('filefoto')){
                  $gbr $this->upload->data();
                //Compress Image
              $this->_create_thumbs($gbr['file_name']);
              $this->session->set_flashdata('msg','<div class="alert alert-info">Image Upload Successful.</div>');
              redirect('upload');
                  }else{
                  echo $this->upload->display_errors();
                }

          }else{
                  echo "image is empty or type of image not allowed";
          }
}

function 
_create_thumbs($file_name){
      // Image resizing config
      $config = array(
          // Large Image
          array(
              'image_library' => 'GD2',
              'source_image'  => './public/assets/img_content/'.$file_name,
              'maintain_ratio'=> FALSE,
              'width'        => 700,
              'height'        => 467,
              'new_image'    => './public/assets/img_content/large/'.$file_name
              
),
          // Medium Image
          array(
              'image_library' => 'GD2',
              'source_image'  => './public/assets/img_content/'.$file_name,
              'maintain_ratio'=> FALSE,
              'width'        => 600,
              'height'        => 400,
              'new_image'    => './public/assets/img_content/medium/'.$file_name
              
),
          // Small Image
          array(
              'image_library' => 'GD2',
              'source_image'  => './public/assets/img_content/'.$file_name,
              'maintain_ratio'=> FALSE,
              'width'        => 100,
              'height'        => 67,
              'new_image'    => './public/assets/img_content/small/'.$file_name
          
));

      $this->load->library('image_lib'$config[0]);
      foreach ($config as $item){
          $this->image_lib->initialize($item);
          if(!$this->image_lib->resize()){
              return false;
          }
          $this->image_lib->clear();
      }
  }
  
In this code I am to upload the only main file its thumbnails are not uploading. What is wrong in this code? Any one can suggest changes in the code so that I can upload image with multiple thumbnails.
Reply
#2

Single upload but with multiple images? Otherwise I wonder why you need three same thumbnails from one single image

To get them from multiple images you need foreach, from just one image you need for loop
Reply
#3

(This post was last modified: 11-23-2022, 05:05 AM by deepakaryan.)

(11-21-2022, 09:02 AM)deepakaryan Wrote: I want to create Multiple Thumbnails from single upload. I am using this code 
 
PHP Code:
function do_upload(){
    $config['upload_path'] = './public/assets/img_content/'//path folder
      $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
      $config['encrypt_name'] = FALSE;

      $this->upload->initialize($config);

    if(!empty($_FILES['filefoto']['name'])){
              if ($this->upload->do_upload('filefoto')){
                  $gbr $this->upload->data();
                //Compress Image
              $this->_create_thumbs($gbr['file_name']);
              $this->session->set_flashdata('msg','<div class="alert alert-info">Image Upload Successful.</div>');
              redirect('upload');
                  }else{
                  echo $this->upload->display_errors();
                }

          }else{
                  echo "image is empty or type of image not allowed";
          }
}

function 
_create_thumbs($file_name){
      // Image resizing config
      $config = array(
          // Large Image
          array(
              'image_library' => 'GD2',
              'source_image'  => './public/assets/img_content/'.$file_name,
              'maintain_ratio'=> FALSE,
              'width'        => 700,
              'height'        => 467,
              'new_image'    => './public/assets/img_content/large/'.$file_name
              
),
          // Medium Image
          array(
              'image_library' => 'GD2',
              'source_image'  => './public/assets/img_content/'.$file_name,
              'maintain_ratio'=> FALSE,
              'width'        => 600,
              'height'        => 400,
              'new_image'    => './public/assets/img_content/medium/'.$file_name
              
),
          // Small Image
          array(
              'image_library' => 'GD2',
              'source_image'  => './public/assets/img_content/'.$file_name,
              'maintain_ratio'=> FALSE,
              'width'        => 100,
              'height'        => 67,
              'new_image'    => './public/assets/img_content/small/'.$file_name
          
));

      $this->load->library('image_lib'$config[0]);
      foreach ($config as $item){
          $this->image_lib->initialize($item);
          if(!$this->image_lib->resize()){
              return false;
          }
          $this->image_lib->clear();
      }
  }
  
In this code I am to upload the only main file its thumbnails are not uploading. What is wrong in this code? Any one can suggest changes in the code so that I can upload image with multiple thumbnails.

There is no error in the code. I getting the error due to XAMP malfunction . In XAMP server gd function is disabled. After enabling the gd function the code is working fine.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB