codeigniter图像上传水印和缩略图

时间:2012-10-03 05:10:28

标签: php codeigniter

我正在使用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();
    }

1 个答案:

答案 0 :(得分:2)

首先执行watermark(),然后执行do_thumb(),删除水印功能$image_cfg['new_image'],或者如果您想使用它,请将$image_cfg['new_image']值传递给do_thumb()。< / p>

另外不要忘记在$image_cfg['new_image']设置do_thumb(),以便创建新的拇指文件而不是重写它

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