Welcome Guest, Not a member yet? Register   Sign In
Image manipulation class
#1

[eluser]frist44[/eluser]
I have a form that uploads a file. I'm doing 2 things. If the width is greater than 500, I'm sizing it down proportionally. And 2. Creating a thumbnail.

My problem is that as the code is below, it'll create the thumbnail, but not the optimize the size. If I comment out one of the other function, they both work individually, but not together. It seems like with the code below, the thumbnail code is actually overwriting the file without any "_thumb" name as it does when it's called on its own.

Here is my code:

Code:
public function upload_picture(){
        
        if ( ! $this->setup_and_load_upload() ){
            show_error('Could not setup and load upload library');
        }
        
        if ( $this->CI->upload->do_upload($this->field_name) ){

            // Dump upload picture details
            $data = $this->CI->upload->data();
            
            // If picture width is larger than 500
            // create a copy and resize image to save
            if ($data['image_width'] > 500) $this->optimize_pic($data['file_name']);
            
            // Create thumbnail
            $this->create_thumbnail($data['file_name']);

  
            return $data;      
        } else {
            echo $this->CI->upload->display_errors();            
            return FALSE;
        }      
    }

    private function optimize_pic($filename) {

        $config['image_library'] = 'gd2';
        $config['source_image'] = $this->upload_path . $filename;
        $config['master_dim'] = 'width';
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 500;
        $config['height'] = 75;
    
        $this->CI->image_lib->initialize($config);
        
        $this->CI->image_lib->resize();
        $this->CI->image_lib->clear();
    }
    
    private function create_thumbnail($filename) {

        $config['image_library'] = 'gd2';
        $config['source_image'] = $this->upload_path . $filename;
        $config['new_image'] = $filename;
        $config['master_dim'] = 'width';
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 100;
        $config['height'] = 75;
    
        //$this->CI->load->library('image_lib', $config);
        $this->CI->image_lib->initialize($config);
        $this->CI->image_lib->resize();
        $this->CI->image_lib->clear();
    }
#2

[eluser]frist44[/eluser]
Nevermind. It was a filename issue being overwritten.




Theme © iAndrew 2016 - Forum software by © MyBB