【发布时间】:2011-12-26 17:08:33
【问题描述】:
我正在尝试让用户上传文件,然后我的函数会将照片调整为 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);
}
}
【问题讨论】:
标签: php codeigniter image-processing