Welcome Guest, Not a member yet? Register   Sign In
Image resize and creating thumb not working together!
#1

I am trying to upload an image to my server. After uploading, I want following actions:

1. If the image is larger than 600Kb, I want to reduce the image quality by 60%
2. If the image is larger than 300Kb, I want to reduce the image quality by 70%
3. After that, want to create thumb of the image.

But these are not working together. Here is my code:

Code:
if(!$this->upload->do_upload('img')){
   // DISPLAY ERROR
}
else{
   $this->CI =& get_instance();
   $this->CI->load->library('image_lib');

    // Resize if image size is larger than 600Kb
   if($this->upload->data('file_size') > 600){
       $config1 =array();
        $config1['image_library']    = 'gd2';
       $config1['source_image']    = $this->upload->data('full_path');
       $config1['quality']              = 60;
       $this->CI->image_lib->initialize($config1);
       $this->CI->image_lib->resize();
       $this->CI->image_lib->clear();
   }
    // Resize if image size is larger than 300Kb
   if($this->upload->data('file_size') > 300){
       $config2 =array();
       $config2['image_library']    = 'gd2';
       $config2['source_image']     = $this->upload->data('full_path');
       $config2['quality']          = 70;
       $this->CI->image_lib->initialize($config2);
       $this->CI->image_lib->resize();
       $this->CI->image_lib->clear();
   }

    // Creating thumbnail of the image
   $config3['image_library']    = 'gd2';
   $config3['source_image']     = $this->upload->data('full_path');
   $config3['quality']          = 70;
   $config3['width']            = 300;
   $config3['create_thumb']     = TRUE;
   $config3['thumb_marker']     = '';
   $config3['new_image']        = 'new_name';
   $this->CI->image_lib->initialize($config3);
   $this->CI->image_lib->resize();
   $this->CI->image_lib->clear();
}


Thanks in advance for your help. Shy
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply


Messages In This Thread
Image resize and creating thumb not working together! - by webdevron - 07-27-2018, 03:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB