0

我想在上传后在多张图片上应用水印。现在图片正在上传,但都没有水印,我也想降低上传图片的质量。

public function do_upload()
{       
        $this->load->library('upload');

        $name_array = array();
        $files = $_FILES;
        $cpt = count($_FILES['userfile1']['name']);
        for($i=0; $i<=$cpt-1; $i++)
        {           
            $_FILES['userfile']['name']= $files['userfile1']['name'][$i];
            $_FILES['userfile']['type']= $files['userfile1']['type'][$i];
            $_FILES['userfile']['tmp_name']= $files['userfile1']['tmp_name'][$i];
            $_FILES['userfile']['error']= $files['userfile1']['error'][$i];
            $_FILES['userfile']['size']= $files['userfile1']['size'][$i];    

            $this->upload->initialize($this->set_upload_options());
            if($data = $this->upload->do_upload()){
                $config['source_image'] = $files['userfile1']['tmp_name'][$i]; //get original image
                $config['wm_type'] = 'overlay';
                $config['wm_overlay_path'] = './portfolio_img/ninja.png';
                $config['quality'] = 50;
                $config['wm_vrt_alignment'] = 'bottom';
                $config['wm_hor_alignment'] = 'right';
                $this->load->library('image_lib', $config);
                $this->image_lib->watermark(); 
            }

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

        return $name_array;
}  

private function set_upload_options()
{   
        //upload an image options
        $config = array();
        $config['upload_path']   = './portfolio_img/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']      = '0';
        $config['overwrite']     = FALSE;

        return $config;
}
4

1 回答 1

2

水印方法需要您传递的图像路径 tem_path 希望这会起作用

试试这个

$config['source_image'] = './portfolio_img/' . $files['userfile1']['name'][$i]

它对我有用

日期

请在循环之前加载库并source_image每次更改名称。

$config['source_image'] = '';
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './portfolio_img/ninja.png';
$config['quality'] = 50;
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'right';
$this->load->library('image_lib', $config);

for($i=0; $i<=$cpt-1; $i++)
{           
    $_FILES['userfile']['name']= $files['userfile1']['name'][$i];
    $_FILES['userfile']['type']= $files['userfile1']['type'][$i];
    $_FILES['userfile']['tmp_name']= $files['userfile1']['tmp_name'][$i];
    $_FILES['userfile']['error']= $files['userfile1']['error'][$i];
    $_FILES['userfile']['size']= $files['userfile1']['size'][$i];    

    $this->upload->initialize($this->set_upload_options());
    if($data = $this->upload->do_upload()){
        $config['source_image'] = './portfolio_img/' . $files['userfile1']['name'][$i]
        $this->image_lib->initialize($config);
        $this->image_lib->watermark(); 
    }

    $name_array[] = $this->upload->data('file_name');
}
于 2016-10-27T06:02:42.370 回答