Welcome Guest, Not a member yet? Register   Sign In
Multiple Image Lib Processing Issue
#1

[eluser]CodyPChristian[/eluser]
Hey guys, been awhile since I've been around here.

I have a function that uploads a file, then it runs two image_lib processes on it.

1. Uploads image
2. Creates thumb of image
3. Crops thumb image
4. Submits data to database

The code I've pasted below I've removed a lot of the code and only left the two processing functions because everything else is working, however the cropping is not working and it doesn't error it just doesn't crop and keeps going.

I want to note once this is working a lot of this will be moved to model functions.

Code:
//previous code nulled out of this paste
//Gets Upload data from upload function.
$upload_data = $this->upload->data();
$filename = $upload_data['file_name'];
//Process filename for thumbnail from original filename.
$filename_thumb = $this->cadmin->ProcessFileName($filename);
//Config for image_lib resizing of thumbnail.
$config1['image_library'] = 'gd2';
$config1['source_image'] = ''.$path_final.$filename.'';
$config1['create_thumb'] = TRUE;
$config1['maintain_ratio'] = TRUE;
$config1['width'] = 100;
$config1['height'] = 100;            
$config1['master_dim'] = 'height';            
$this->load->library('image_lib', $config1);            
$this->image_lib->initialize($config1);
$this->image_lib->resize();
//if fails take to page and display errors
if(!$this->image_lib->resize()){
    $data['error'] = '<div class="error_msg">'.$this->image_lib->display_errors().'</div>';
    $this->load->view('admin/pages/library_add', $data);
} else {
//if success clear previous image_lib config and keep going
    $this->image_lib->clear();
    $config2['image_library'] = 'gd2';
    $config2['source_image'] = ''.$path_final.$filename_thumb.'';
    $config2['x_axis'] = '100';
    $config2['y_axis'] = '100';
//crops image based on config above
    $this->load->library('image_lib', $config2);            
    $this->image_lib->initialize($config2);
    $this->image_lib->crop();
//if fails take to page and display errors
    if(!$this->image_lib->crop()){
        $data['error'] = '<div class="error_msg">'.$this->image_lib->display_errors().'</div>';
        $this->load->view('admin/pages/library_add', $data);
    } else {
//if success submit to db and redirect to appropriate place
        //Submits to DB - code nulled out of this paste
    }
}

Thanks!
#2

[eluser]CodyPChristian[/eluser]
About 10 hours of fighting later, many mountain dews and the great help of sholsinger on the IRC it all came down to a simple fix of something being missing.

Code:
$config2['width'] = 100;
$config2['height'] = 100;            
$config2['x_axis'] = '0';
$config2['y_axis'] = '0';        
$config2['maintain_ratio'] = FALSE;
$config2['create_thumb'] = FALSE;


Final working function!
Code:
function library_create()
    {
        $data = $this->cadmin->siteInfo();
        $data['cpage'] = 'slideshows';
        $data['scpage'] = 'library_add';
        $data['submenu'] = true;
        $path_final = $this->config->item('site_path').'static/images/slideshows/';        
        $config['upload_path'] = $path_final;
        $config['allowed_types'] = 'jpg|png';
        $config['max_size']    = '2048';
        $config['max_width']  = '1000';
        $config['max_height']  = '2000';
        $this->load->library('upload', $config);
        if(!$this->upload->do_upload()){
            $data['error'] = '<div class="error_msg">'.$this->upload->display_errors().'</div>';
            $this->load->view('admin/pages/library_add', $data);
        } else {
            $upload_data = $this->upload->data();
            $filename = $upload_data['file_name'];
            $filename_thumb = $this->cadmin->ProcessFileName($filename);
            $config1['source_image'] = $path_final.$filename.'';
            $config1['create_thumb'] = TRUE;
            $config1['maintain_ratio'] = TRUE;
            $config1['width'] = 100;
            $config1['height'] = 100;            
            $config1['master_dim'] = 'height';            
            $this->image_lib->initialize($config1);
            if(!$this->image_lib->resize()){
                $data['error'] = '<div class="error_msg">'.$this->image_lib->display_errors().'</div>';
                $this->load->view('admin/pages/library_add', $data);
            } else {
                $this->image_lib->clear();
                $config2['image_library'] = 'gd2';
                $config2['source_image'] = ''.$path_final.$filename_thumb.'';
                $config2['width'] = 100;
                $config2['height'] = 100;            
                $config2['x_axis'] = '0';
                $config2['y_axis'] = '0';        
                $config2['maintain_ratio'] = FALSE;
                $config2['create_thumb'] = FALSE;
                $this->image_lib->initialize($config2);
                if(!$this->image_lib->crop()){
                    $data['error'] = '<div class="error_msg">'.$this->image_lib->display_errors().'</div>';
                    $this->load->view('admin/pages/library_add', $data);
                } else {
                    $data['error'] = '';
                    $nicename = $this->input->post('nicename');
                    $this->db->set('filename', $filename);
                    $this->db->set('filename_thumb', $filename_thumb);
                    $this->db->set('nicename', $nicename);
                    $this->db->insert('slideshow_library');
                    redirect("admin/slideshows/library");
                }
            }
        }
    }
#3

[eluser]Jondolar[/eluser]
It also looked like you were calling the resize() and crop() functions twice. I guess it was writing the image and then writing over it without you knowing it. I'm glad it's working and that you posted your code for us (me) to be able to use/learn.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB