上载调整大小的图像CI

时间:2019-07-15 09:07:17

标签: php codeigniter

在设置调整大小代码之前,我正在设置上传文件。及其正常过程,但是添加调整大小代码后,我的控制器无法正常工作。你能帮我吗?我正在尝试,但是没有用。

还有另一个问题,我上传的图片文件大小不能超过2MB。

这是我在网上商店上的工作。

public function submit_image()
{
    $input_name = $_POST['input_name'];
    $input_email = $_POST['input_email'];
    $input_code_transaction = $_POST['input_code_transaction'];

    $config['file_name'] = $input_code_transaction;
    $config['overwrite'] = TRUE;
    $config['upload_path']          = './img/';
    $config['allowed_types']        = 'gif|jpg|png|jpeg';
    $config['max_size']             = 50000000;
    $config['max_width']            = 6000;
    $config['max_height']           = 4000;

    $this->upload->initialize($config);

    if(!empty($_FILES['filefoto']['name'])) {
        if ($this->upload->do_upload('doc')) {
            $gbr = $this->upload->data();
            //Compress Image
            $config['image_library']='gd2';
            $config['source_image']='./img/'.$gbr['file_name'];
            $config['create_thumb']= FALSE;
            $config['maintain_ratio']= FALSE;
            $config['quality']= '50%';
            $config['width']= 1280;
            $config['height']= 720;
            $config['new_image']= './img/'.$gbr['file_name'];
    $this->load->library('upload', $config);
            $this->upload->resize();        

    $data = $upload_data = $this->upload->data();
    $input_picture = $this->upload->do_upload('doc');
                }
        }
 }

1 个答案:

答案 0 :(得分:0)

上传库没有用于调整图像大小的内置功能。<​​/ p>

整个部分:

$config['image_library']='gd2';
            $config['source_image']='./img/'.$gbr['file_name'];
            $config['create_thumb']= FALSE;
            $config['maintain_ratio']= FALSE;
            $config['quality']= '50%';
            $config['width']= 1280;
            $config['height']= 720;
            $config['new_image']= './img/'.$gbr['file_name'];
    $this->load->library('upload', $config);
            $this->upload->resize();        

    $data = $upload_data = $this->upload->data();
    $input_gambar = $this->upload->do_upload('doc');

需要引用image_lib图像调整器代码点火器使用的https://www.codeigniter.com/user_guide/libraries/image_lib.html

所以:

    if ($this->upload->do_upload('doc')) {
        $gbr = $this->upload->data();
        //Compress Image


        $imlib['image_library'] = 'gd2';
        $imlib['source_image'] = './img/' . $gbr['file_name'];
        $imlib['create_thumb'] = FALSE;
        $imlib['maintain_ratio'] = FALSE;
        $imlib['quality'] = '50%';
        $imlib['width'] = 1280;
        $imlib['height'] = 720;
        $imlib['new_image'] = './img/resized_' . $gbr['file_name'];
        $this->load->library('image_lib', $imlib);
        if (!$this->image_lib->resize()) {
            show_error($this->image_lib->display_errors());
        }
        $yourouputimage = './img/resized_' . $gbr['file_name'];
    }