0
我想讓用戶上傳他們的個人資料圖片時,它會將其大小調整爲180x180的大小以適合個人資料圖片框。然後,我希望它也創建圖像的縮略圖,所以我可以用它的帖子等,這是我的代碼現在所擁有的:CodeIgniter - 縮放圖像並創建其他縮略圖
function do_upload_profilepicture()
{
$this->load->model('model_users');
$userID = $this->model_users->getUserID($this->session->userdata('username'));
$config['upload_path'] = './img/profilepictures/';
$config['allowed_types'] = 'jpg|png';
$config['overwrite'] = TRUE;
$config['file_name'] = $userID;
$config['max_size'] = '500';
$config['max_width'] = '1920';
$config['max_height'] = '1028';
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_profilepic_form', $error);
}
else
{
$upload_data = $this->upload->data();
$resize['image_library'] = 'gd2';
$resize['source_image'] = $upload_data['full_path'];
$resize['maintain_ratio'] = FALSE;
$resize['width'] = 180;
$resize['height'] = 180;
$this->load->library('image_lib', $resize);
$this->image_lib->resize();
$this->model_users->setProfilePic($userID, $upload_data['orig_name']);
redirect('upload/create_thumb/' . $upload_data['orig_name']);
}
}
function create_thumb() {
$this->load->model('model_users');
$userID = $this->model_users->getUserID($this->session->userdata('username'));
$imgname = $this->model_users->parseURL($_SERVER['REQUEST_URI'], 1);
$source_path = $imgsrc;
$config_manip = array(
'image_library' => 'gd2',
'source_image' => 'img/profilepictures/' . $imgname,
'new_image' => base_url() . 'img/profilepictures/thumbs/' . $imgname,
'maintain_ratio' => TRUE,
'width' => 50,
'height' => 50
);
$this->load->library('image_lib', $config_manip);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
// clear //
$this->image_lib->clear();
redirect('userprofile/home/' . $userID);
}
}
什麼情況是它不是創建新的文件,這是爲什麼這個?有沒有更簡單的方法來做到這一點?