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
#2

@webdevron,

Are you seeing any errors?
Reply
#3

(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.
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply
#4

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?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(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
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply
#6

@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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB