我的上传和调整图片处理程序代码:
function upload() {
//check if admin is logged in.
if ($this->session->userdata('is_logged') == 1) {
//loading the configuration for the upload library.
$config = array();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '7000';
$config['max_width'] = '6000';
$config['max_height'] = '5000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$data['redirect_msg'] = $this->upload->display_errors() . '<br /> go back to ' . anchor('admin/', 'main page');
$this->load->view('redirect', $data);
} else {
//getting the image's information, in order to resize it.
$upload_data = $this->upload->data();
$image_path = $upload_data['full_path'];
/* loading the configuration for the image manuiplation library. */
$config['image_library'] = 'gd';
$config['source_image'] = $image_path;
$config['width'] = '800';
$config['height'] = '600';
$config['maintain_ratio'] = FALSE; //tried setting it to TRUE aswell.
//loading the library
$this->load->library('image_lib', $config);
//starting the resize proccess.
$this->image_lib->resize();
//checking if the is an error in the resizing proccess.
if (!$this->image_lib->resize()) {
/* displaying the errors */
$data['redirect_msg'] = $this->image_lib->display_errors();
$this->load->view('redirect', $data);
} else {
/* show positive message. */
$data['redirect_msg'] = 'Upload successful!<br />redirecting to ' . anchor('admin/', 'homepage') . ' in 3 seconds';
$this->load->view('redirect', $data);
//saving the image name to a database table, so we can retrieve it when needed(for the slideshow).
$this->db_model->save_image($upload_data['orig_name']);
//doing the redirect.
header('refresh:3;url=' . site_url('admin/'));
}
}
} else { //if not logged in, show negative message.
$data['redirect_msg'] = 'you are not logged in. < br/> login ' . anchor('admin/', 'here');
$this->load->view('redirect', $data);
}
}
答案 0 :(得分:0)
您正在调整该图像的大小两次:
//starting the resize proccess.
$this->image_lib->resize();
//checking if the is an error in the resizing proccess.
if (!$this->image_lib->resize()) {
只做一次:
//starting the resize proccess.
//checking if the is an error in the resizing proccess.
if (!$this->image_lib->resize()) {