codeigniter image upload watermark and thumbnail

一个人想着一个人 提交于 2019-12-24 14:54:15

问题


i am uploading an image using CI upload library work fine, problem with watermarking and image thumbnail, if id do watermarking first and then thumbnail, its doing watermarking to original image but also re-sized it thumbnail size but not keeping original size image with watermark too, if i do thumbnail first then watermark it work fine but i want thumbnail also watermarked here is my code

$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:


Execute watermark() first, then do_thumb(), remove $image_cfg['new_image'] at watermark function or if you want to use it, pass $image_cfg['new_image'] value to do_thumb().

Also dont forget to set $image_cfg['new_image'] at do_thumb() so it create new thumb file not rewrite it

The problem why your thumb not contain watermark is because you use original image not the watermarking image as the image source for the thumb. hope you understand what i mean cos english is not my first language, php it is ..



来源:https://stackoverflow.com/questions/12702234/codeigniter-image-upload-watermark-and-thumbnail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!