Welcome Guest, Not a member yet? Register   Sign In
Resizing an uploaded image
#1

[eluser]Stompfrog[/eluser]
Hi,

I am trying to allow website users to upload an avatar to their profiles. I have managed to create a working file upload form thanks to the CI documentation and forum examples. The function that i have in my controller is like this...
Code:
function avatar(){

    $config['upload_path'] = './avatars/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']    = '0';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $config['encrypt_name'] = TRUE;
    $config['remove_spaces'] = TRUE;
    
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload()){
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('static/header', $data);
        $this->load->view('avatar_view', $error);
        $this->load->view('static/footer');
    }    
    else{
        $data = array('upload_data' => $this->upload->data());
        $upload_data = $this->upload->data();
            $userAvatar = "/avatars/".$upload_data['file_name'];
        avatar2($userAvatar);
    }        
}

This is working fine but the avatars need to be a 60px x 60px square before they can be used on my site. This is where avatar2() comes in...

Code:
function avatar2($userAvatar){

    $this->load->library('image_lib');

    $config['image_library'] = 'GD2';
    $config['source_image'] = $userAvatar;
    $config['x_axis'] = '60';
    $config['y_axis'] = '60';
    $config['new_image'] = "thisisatest.jpg";
    
    $this->image_lib->initialize($config);
    
    if ( ! $this->image_lib->crop())
    {
        echo $this->image_lib->display_errors();
    }
    
    echo "this is the end";

}

I am not getting any errors and the echo and the end of the function is appearing fine.

The original uploaded file is appearing in the /avatars folder but there is no resized thumbnail.

I am using MAMP on Mac OSX. Can anyone help me to work out where I am going wrong?

Thanks


Messages In This Thread
Resizing an uploaded image - by El Forum - 09-13-2008, 11:13 AM
Resizing an uploaded image - by El Forum - 09-13-2008, 11:30 AM
Resizing an uploaded image - by El Forum - 09-15-2008, 08:52 AM
Resizing an uploaded image - by El Forum - 09-15-2008, 10:22 AM
Resizing an uploaded image - by El Forum - 09-15-2008, 12:24 PM
Resizing an uploaded image - by El Forum - 09-20-2008, 08:31 AM
Resizing an uploaded image - by El Forum - 12-06-2008, 09:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB