Welcome Guest, Not a member yet? Register   Sign In
how to generate exact same size thumbnail for different images in codeigniter
#1

[eluser]Irshad Sheikh[/eluser]
Hello,

I can generate the thumbnails of images but they all don't look
same in the size(same in height & width).

Code:
$config['upload_path'] = $path.'/user_images/';
                    $config['allowed_types'] = 'gif|jpg|png|bmp';
                    $config['max_size']='400';
                    $config['max_width'] = '1024';
                    $config['max_height']= '768';
                
                $this->load->library('upload', $config);
            
                if ( ! $this->upload->do_upload())
                {
              
                                $data['error'] = $this->upload->display_errors();
                  
                }
                        else
                        {    
                                $data = array('upload_data' => $this->upload->data());
                    $config['image_library'] = 'gd2';
                //    $config['source_image'] = '/opt/lampp/htdocs/TheInterest.com/image/'.$data['upload_data']['file_name'];
                                $config['source_image'] = $path.'/user_images/'.$data['upload_data']['file_name'];
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = 100;
                    $config['height'] = 70;
                    $config['new_image'] = $path.'/user_images/thumbs/';
            
                    $this->load->library('image_lib', $config);
                    $this->image_lib->resize();
        
                      
                        }
                     }

thanks in advance .
#2

[eluser]Dam1an[/eluser]
Are they the same size going in? Cause the 'maintain ratio' will be the cause of the problem if not
#3

[eluser]TheFuzzy0ne[/eluser]
Assuming your images are larger than 100px in width, and 70px in height, your resulting images should be either 100px in width and less that 70px in height, or 70px in height and less than 100px in width.
#4

[eluser]Michael Wales[/eluser]
Let's say you want all images to be 100 x 100:

Use a conditional to determine which dimension is the smallest, and resize by that dimension down to 100px. Then, crop the image down to 100px on the other dimension (offset by half the difference of the thumbnail's size and 100px - this will cause it to crop the center of the image).

The crop afterwards is to prevent the "squishy/stretchy" appearance if you enforce a particular size on both dimensions.
#5

[eluser]Irshad Sheikh[/eluser]
Maintain Ratio should be false..
#6

[eluser]stef25[/eluser]
Michael Wales' response is correct




Theme © iAndrew 2016 - Forum software by © MyBB