小郑 发表于 2011-12-26 17:55:12

上传图片,原图打完水印,再生成缩略图

                        $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,这样才不会把打了水印的原图给覆盖!

thenbsp 发表于 2011-12-30 17:00:10

照理说应该先缩略图再水印吧。
页: [1]
查看完整版本: 上传图片,原图打完水印,再生成缩略图