CodeIgniter Forums
Upload, Crop, Resize, and Thumb - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Upload, Crop, Resize, and Thumb (/thread-25438.html)



Upload, Crop, Resize, and Thumb - El Forum - 12-11-2009

[eluser]merrick.christensen[/eluser]
Ok. I'm not sure what the heck is going on here. I am getting very frustrated and would appreciate any help hat could be offered.

The user is uploading an image. It sends them to a crop utility, they crop and it resizes, then it would create a thumb from the crop. My issue is that it is applying the thumb resize to the crop rather then creating a new one. Even thought the property is set, in fact if I access the process_thumb function directly it will create a thumb, but not with PHP. Any help would be so appreciated.

Code:
<?php

function process_image($image_url)
    {
        $config['image_library'] = 'gd2';
        $config['source_image'] = './uploads/' . $image_url;
        $config['maintain_ratio'] = FALSE;
        $config['width'] = $this->input->post('w');
        $config['height'] = $this->input->post('h');
        $config['x_axis'] = $this->input->post('x');
        $config['y_axis'] = $this->input->post('y');
        
        $this->image_lib->initialize($config);
        
        if ( ! $this->image_lib->crop())
        {
            echo $this->image_lib->display_errors();
        }
        else {
        if (! $this->process_resize($image_url)){
                echo "Failed Resize";
            } else{
                if(! $this->process_thumb($image_url)){
                    echo "Failed Thumb";
                } else{
                    echo "success";
                }
            }
        }
    }
    
    function process_resize($image_url)
    {    
        $this->image_lib->clear();
        $config['image_library'] = 'gd2';
        $config['source_image'] = './uploads/' . $image_url;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 162;
        $config['height'] = 246;

        $this->image_lib->initialize($config);
        
        if ( ! $this->image_lib->resize()){
            return false;
        } else{
            return true;        
        }
    }
    
    function process_thumb($image_url)
    {
        $this->image_lib->clear();
        $config['image_library'] = 'gd2';
        $config['source_image'] = './uploads/' . $image_url;
        $config['maintain_ratio'] = TRUE;
        $config['create_thumb'] = TRUE;
        $config['width'] = 32;
        $config['height'] = 32;
        
        $this->image_lib->initialize($config);
        
        //I resize and all that goodness
        if(! $this->image_lib->resize()){
            //echo $this->image_lib->display_errors();
            return false;
        } else{
            //echo "Nice";
            return true;
        }    
    }



Upload, Crop, Resize, and Thumb - El Forum - 12-11-2009

[eluser]Krzemo[/eluser]
I cant see
Code:
$config['new_image'] = '/path/to/new_image.jpg';
anywhere in your code...


Upload, Crop, Resize, and Thumb - El Forum - 12-12-2009

[eluser]Isern Palaus[/eluser]
You can take a look to the library Images posted by JoostV:

http://codeigniter.com/wiki/Category:Libraries::Images/