Hi people! How's going?
Today I'm here to ask you something about the image manipulation. I studied it a lot, but I need help with something.
I'm making a "Change profile picture" like facebook/instagram/twitter/......and more.
I want the image that user upload becomes smaller, not in size(width and height I mean) but in dimension. Instead: I've an image of 4mb -> it must be smaller than 4mb when the user upload on my website.
And do you have some suggestion about display the image in profile user? Instead the image has 800 as width 400 as height and my profile-box is 215w x 215h, how can I crop the image without lose anything?
I post here my actual upload function, maybe you can help me! Thank you
PHP Code:
public function changeProfilePicture(){
$config['upload_path'] = './uploads/images/profile/pictures/';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('photo_input'))
{
$error = array('error' => $this->upload->display_errors());
echo json_encode($error);
}
else
{
$info = $this->upload->data();
$a = array(
'user_id' => $this->session->userdata('uid'),
'image' => $info['file_name']
);
$d = array(
'success' => TRUE
);
$p = array(
'fail' => TRUE
);
//$data = array('upload_data' => $this->upload->data());
if($this->uploadModel->addImagePicture($a)){
//$info;
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $info['full_path'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['height'] = "215";
$config['width'] = "215";
$config['new_image'] = "./uploads/images/profile/pictures/"; //you should have write permission here..
$this->image_lib->initialize($config);
$this->image_lib->resize();
echo json_encode($d);
} else {
exit(json_encode($p));
}
}
}
(Yes, actually I resize the image to 215h 215w, but I don't want do this because if the user click on the image, obviously, he'll see that 215x215 and not with the real dimensions)