1

我正在使用 CI 上传库上传图像工作正常,水印和图像缩略图问题,如果 id 先水印然后缩略图,它对原始图像进行水印,但也重新调整缩略图大小但不保持原始大小的图像带水印同样,如果我先做缩略图然后给它加水印它工作正常,但我希望缩略图也加水印这是我的代码

$this->do_thumb('file_name');
$this->watermark('file_name');

function watermark($filename){
        $image_cfg = array();
        $image_cfg['image_library'] = 'GD2';
        $image_cfg['source_image'] = 'upload/' . $filename;
        $image_cfg['wm_overlay_path'] = 'upload/watermark.png';
        $image_cfg['new_image'] = 'upload/mark_'.$filename;
        $image_cfg['wm_type'] = 'overlay';
        $image_cfg['wm_opacity'] = '10';
        $image_cfg['wm_vrt_alignment'] = 'bottom';
        $image_cfg['wm_hor_alignment'] = 'right';
        $image_cfg['create_thumb'] = FALSE;

        $this->image_lib->initialize($image_cfg);
        $this->image_lib->watermark();
        $this->image_lib->clear();

//        echo $this->image_lib->display_errors();
//        die();

    }

    function do_thumb($filename) {
        $image_cfg['image_library'] = 'GD2';
        $image_cfg['source_image'] = 'upload/' . $filename;
        $image_cfg['create_thumb'] = TRUE;
        $image_cfg['maintain_ratio'] = TRUE;
        $image_cfg['width'] = '200';
        $image_cfg['height'] = '175';
        $this->load->library('image_lib');
        $this->image_lib->initialize($image_cfg);
        $this->image_lib->resize();
        $this->image_lib->clear();
    }
4

1 回答 1

2

先执行watermark(),然后do_thumb(),删除$image_cfg['new_image']水印功能,或者如果你想使用它,将$image_cfg['new_image']值传递给do_thumb().

也不要忘记设置$image_cfg['new_image']do_thumb()所以它会创建新的拇指文件而不是重写它

您的拇指不包含水印的问题是因为您使用原始图像而不是水印图像作为拇指的图像源。希望你明白我的意思,因为英语不是我的母语,php 是..

于 2013-02-12T11:47:26.647 回答