我試圖讓用戶上傳一個文件,然後我的功能將調整大小的照片像800x600,然後調整到165x165文件。通過我的代碼,它只能將其重新設置爲165x165,但如果我對該部分進行評論,則會將其重新調整爲800x600。試圖調整圖像兩次在一個函數中,它只是調整一次
我能做些什麼來調整它們的大小?
/**
* addPhoto - function which shows the add photo page
*/
function addPhoto($album)
{
$album = rawurldecode($album);
ini_set('upload_max_filesize', '4M');
ini_set('post_max_size', '12M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
$config['upload_path'] = './assets/images/photoAlbums/'.$album.'/';
$config['allowed_types'] = 'jpg|jpeg|pjpeg';
$config['max_size'] = '4096'; // that's 4MBs
$config['max_width'] = '4000';
$config['max_height'] = '3000';
$config['remove_space'] = TRUE;
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('userFile')) { // if there are errors uploading the file...
$content_data['error'] = array('error' => $this->upload->display_errors());
} else { // else there are NO errors, we need to resize it, and ditch that huge ass original
$image = $this->upload->data();
$uploadedFile = $image['file_name'];
$this->load->library('image_lib');
$thumbConfig['image_library'] = 'gd2';
$thumbConfig['source_image'] = $image['full_path'];
$thumbConfig['create_thumb'] = FALSE;
$thumbConfig['maintain_ratio'] = TRUE;
$thumbConfig['width'] = 800;
$thumbConfig['height'] = 600;
$this->image_lib->initialize($thumbConfig);
if (! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
$thumbConfig['image_library'] = 'gd2';
$thumbConfig['source_image'] = $image['full_path'];
$thumbConfig['create_thumb'] = TRUE;
$thumbConfig['maintain_ratio'] = FALSE;
$thumbConfig['width'] = 165;
$thumbConfig['height'] = 165;
$this->image_lib->initialize($thumbConfig);
if (! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
$content_data['firstName'] = $this->session->userdata('firstName');
$data['sess'] = $this->session;
$data['content'] = $this->load->view('member/addPhoto_success', $content_data, true);
$this->load->view('template/admin', $data);
}
}
這裏的派對真的很晚,但用戶指南說「create_thumb」設置會創建一個縮略圖(AND PRESERVE THE ORIGINAL)。爲什麼你必須在這種情況下指定new_image? 「create_thumb」的存在是否適合我們? – Greg