调整图像大小在代码点火器3中不起作用

问题描述 投票:0回答:1

我一直在尝试在Codeigniter 3中调整图像的大小,但是没有运气!我在ddoo_upload()函数中具有调整大小,但不确定发生了什么错误!

这是我尝试过的图像上传,下面的代码显示了我的上传功能(并在其中调整大小)

if (isset($_FILES['destiimg']) && $_FILES['destiimg']['name'] != '') {
                    $filename = $this->ddoo_upload('destiimg', '2000' , '336');
} else {
                    $filename = NULL;
} 



function ddoo_upload($filename, $width, $height)
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'jpg|jpeg|png|gif';  
    $config['overwrite'] = FALSE;
    $config['encrypt_name'] = TRUE;

    $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload($filename)) {
        echo $this->upload->display_errors();die();
        return NULL;
    } else {

        $data = $this->upload->data();          
        $filename = $data['file_name'];

        $config1['image_library'] = 'gd2';
        $config1['source_image'] = $this->upload->upload_path.$this->upload->file_name;
        //$config1['create_thumb'] = TRUE;
        $config1['maintain_ratio'] = FALSE;
        $config1['width'] = $width;
        $config1['height'] = $height;

        $this->load->library('image_lib', $config1);
        $this->image_lib->resize();

        return $filename;
    }
}

上传正常,但调整大小时出现问题。

resize codeigniter-3 image-uploading
1个回答
0
投票

[加载image_lib时缺少一些配置选项。

manual,您没有指定source_image(和其他选项)。

如果要使用高级功能,则有一个不错的库,名为Image Moo。它比较老,但是可以和CI3一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.