Welcome Guest, Not a member yet? Register   Sign In
Image Resizing Newbie Help
#1

[eluser]brixxster[/eluser]
Hello again guys,

I have a code here that's suppose;

1. Save the image in "/uploads" directory.
2. If the image is saved, it will find the file to make a thumbnail version of it and save to "/uploads/thumbs" directory.

I have it running successfully in saving the image in the /uploads directory but can't seem to find the error why it is not saving the thumbnail version under /upload/thumbs directory. Please help.

The code.

Code:
function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->load->view('upload_form', $error);
        }    
        else    // when file is uploaded, start making thumbnails
        {
            //$data = array('upload_data' => $this->upload->data());
            $data = array('upload_data' => $this->upload->data());
            
            // load image library
            $this->load->library('image_lib');
            
            // set arrays
            
            $config2['image_library'] = 'gd';
            $config2['source_image'] = '/uploads/' . $data['upload_data']['file_name'];
            $config2['create_thumb'] = TRUE;
            $config['new_image'] = '/uploads/thumbs/' . $data['upload_data']['file_name'];
            $config2['maintain_ratio'] = TRUE;
            $config2['width'] = 75;
            $config2['height'] = 50;
            
            $this->load->library('image_lib', $config2);
            $this->image_lib->resize();
                        
            $this->load->view('upload_success', $data);
        }
    }
#2

[eluser]cereal[/eluser]
Change $config['new_image'] to $config2['new_image']

Smile
#3

[eluser]brianw1975[/eluser]
as an aside, just to make sure: verify that /uploads/thumbs/ is writable
#4

[eluser]adaxa[/eluser]
Good idea is to check if resize() is successful or not. By default no errors appear.
You can override this using simple check like this:

Code:
if ( ! $this->image_lib->resize())
{
        echo $this->image_lib->display_errors();                
}




Theme © iAndrew 2016 - Forum software by © MyBB