CodeIgniter Forums
Image resize and creating thumb not working together! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Image resize and creating thumb not working together! (/showthread.php?tid=71283)



Image resize and creating thumb not working together! - webdevron - 07-27-2018

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


RE: Image resize and creating thumb not working together! - php_rocs - 07-27-2018

@webdevron,

Are you seeing any errors?


RE: Image resize and creating thumb not working together! - webdevron - 07-27-2018

(07-27-2018, 05:48 AM)php_rocs Wrote: @webdevron,

Are you seeing any errors?

No there is no error. Just not working all together.


RE: Image resize and creating thumb not working together! - InsiteFX - 07-27-2018

You did not say where this code is! I'am guessing that it's in a library
because you are using the CI Controller object.

Where is this code located?


RE: Image resize and creating thumb not working together! - webdevron - 07-27-2018

(07-27-2018, 09:28 AM)InsiteFX Wrote: You did not say where this code is! I'am guessing that it's in a library
because you are using the CI Controller object.

Where is this code located?

This is the snippet of a function in main controller. This function is uploading image to my server. After uploading, I want to Reduce its size and Create a thumbnail


RE: Image resize and creating thumb not working together! - John_Betong - 07-27-2018

@webdevron,

Take a look at https://AmpProject.org because image dimensions are not mandatory as they can fit inside any fixed or responsive parent container.

https://johns-jokes.cf/amp?app=2

Notice the web-page source script, about a dozen CSS lines are required to format the image.

And not forgetting that images are stored freely using the Google CDN Cache Smile