CodeIgniter Forums
how to generate exact same size thumbnail for different images in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to generate exact same size thumbnail for different images in codeigniter (/showthread.php?tid=20158)



how to generate exact same size thumbnail for different images in codeigniter - El Forum - 06-30-2009

[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 .


how to generate exact same size thumbnail for different images in codeigniter - El Forum - 06-30-2009

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


how to generate exact same size thumbnail for different images in codeigniter - El Forum - 06-30-2009

[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.


how to generate exact same size thumbnail for different images in codeigniter - El Forum - 06-30-2009

[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.


how to generate exact same size thumbnail for different images in codeigniter - El Forum - 07-07-2009

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


how to generate exact same size thumbnail for different images in codeigniter - El Forum - 08-18-2009

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