0

我有一个上传图片 jpg/gif/etc 的上传表单,我用它为我用于我的网站的画廊上传一些图片(图片格式为 Jpg),但不幸的是它不适用于某些图片(它使一切变黑,并在左上角(0, 0)显示调整大小的图像)。
我尝试在线调整图像大小并且它没有问题,所以我认为问题不在于图像本身,它在库/配置中。

我的上传和调整图像处理程序代码:

 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);
        }
    }
4

1 回答 1

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()) {
于 2012-05-20T22:12:08.640 回答