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

[eluser]doccer[/eluser]
I liked the logic behind these functions, but decided to put them all in one function.
The problem with the previous code tho is that the config data for the resize method needs to be re initialized.

The following works perfect. It takes a non-square image, squares it, and crops it with out distortion.

Quote: $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('includes/header', $this->data);
$this->load->view('includes/menu_bar');
$this->load->view('image_upload_view', $error);
$this->load->view('user_view_sidebar');
$this->load->view('includes/footer', $this->footer);
}
else
{
$data = array('upload_data' => $this->upload->data());
$upload_data = $this->upload->data();
$width = $upload_data['image_width'] ;
$height = $upload_data['image_height'] ;

$config['image_library'] = 'gd2';
$config['source_image'] = "./avatars/".$upload_data['file_name'];
$config['maintain_ratio'] = FALSE;
$config['quality'] = 100;


if($height>$width){
$config['x_axis'] = 0;
$config['y_axis'] = ($height-$width)/2;
$config['height'] = $width;
$config['width'] = $width;
}else{
$config['y_axis'] = 0;
$config['x_axis'] = ($width-$height)/2;
$config['height'] = $height;
$config['width'] = $height;
}

$this->load->library('image_lib', $config);
$this->image_lib->crop();

$config['maintain_ratio'] = FALSE;
$config['height'] = 60;
$config['width'] = 60;

$this->image_lib->initialize($config);
$this->image_lib->resize();

//Show success page
$this->session->set_flashdata('message','You successfully uploaded your avatar.');
redirect('profile/edit/avatar');


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