Welcome Guest, Not a member yet? Register   Sign In
Image upload: original, large and thumb
#1

[eluser]a.g.r.c[/eluser]
Hey guys,

I've been inactive on the boards for a while but i've re-visited the beautiful CI.

At my "old" place of work they used it a lot and it seemed to good an opportunity to get back into it.

Having watched a tutorial over at NetTuts in regards to image uploads and thumbs, and then querying the docs. (Tutorial was clearly from the docs :p) i've ran into a problem.

There is a method called createThumb and also createLarge. So once all methods run I should have 1 uploaded and 2 other outputted images.

It doesn't seem to be writing the large image, and having searched the web it took me to a post here.

Code:
$this->image_lib->clear();

Not sure if this is needed, it seems as if the large is simply writing over the original thumb but not taking the new config parameters.

Here is the code below.

Code:
function uploadImage()
    {
        $config['upload_path'] = 'assetts/uploads/img/';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '1000';
        $config['max_width'] = '1680';
        $config['max_height'] = '1250';                        
        
        $this->load->library('upload', $config);
        
        if(!$this->upload->do_upload()) echo $this->upload->display_errors();
        else
        {
            $fInfo = $this->upload->data();
            $data['uploadInfo'] = $fInfo;
            
            $this->_createThumb($fInfo['file_name']);            
            $data['thumb_name'] = $fInfo['raw_name'] . '_thumb' . $fInfo['file_ext'];
            
            $this->_createLarge($fInfo['file_name']);
            $data['large_name'] = $fInfo['raw_name'] . '_large' . $fInfo['file_ext'];
            
            $this->load->view('upload_success', $data);    
        }
    }
    
    function _createThumb($fileName)
    {
        $config['image_library'] = 'gd2';
        $config['source_image'] = 'assetts/uploads/img/'.$fileName;    
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 200;
        $config['height'] = 200;
        
        $this->load->library('image_lib', $config);
        
        if(!$this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        }
    }
    
    function _createLarge($fileName)
    {
        $config['image_library'] = 'gd2';
        $config['source_image'] = 'assetts/uploads/img/'.$fileName;    
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 800;
        $config['height'] = 800;
        
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        }
    }

Any help would be greatly appreciated.

Thanks in advance

Alistair Smile
#2

[eluser]Skuja[/eluser]
I havent used image lib for a while, but i think it helped if you cleared old configuration values
Code:
$this->image_lib->clear();
before you initialized new image_lib instance.




Theme © iAndrew 2016 - Forum software by © MyBB