用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3071|回复: 1
收起左侧

[版本 2.x] 上传图片,原图打完水印,再生成缩略图

[复制链接]
发表于 2011-12-26 17:55:12 | 显示全部楼层 |阅读模式
PHP复制代码
                        $this->load->library('image_lib');
                        //添加水印
                        $config['source_image'] =$this->config->item('photo_path').$ImgName;
                        $config['wm_type'] = 'overlay';
                        $config['quality'] = 100;
                        $config['wm_overlay_path']='upload/shui.png';
                        $config['wm_vrt_alignment'] = 'middle';
                        $config['wm_hor_alignment'] = 'center';        
                        $this->image_lib->initialize($config);
                        if(!$this->image_lib->watermark()){
                                 echo $this->image_lib->display_errors();
                        }
                        $this->image_lib->clear();             
                        //生成缩略图
                        $config['image_library'] = 'gd2';
                        $config['source_image'] = $this->config->item('photo_path').$ImgName;
                        $config['create_thumb'] = TRUE;
                        $config['maintain_ratio'] = TRUE;
                        $config['width'] = $this->config->item('photo_width');
                        $config['height'] = $this->config->item('photo_height');
                        $config['new_image'] = $this->config->item('photo_path').$ImgRawName."_thumb".$ImgType;
                        $this->image_lib->initialize($config);
 
                        $this->image_lib->resize()
 
复制代码

注意的两点,水印打完,需要initialize,缩略图的时候,设置new_image,这样才不会把打了水印的原图给覆盖!
发表于 2011-12-30 17:00:10 | 显示全部楼层
照理说应该先缩略图再水印吧。

本版积分规则