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

[版本 2.x] 加水印和创建缩略图不能同时使用!

[复制链接]
发表于 2011-10-11 22:06:10 | 显示全部楼层 |阅读模式
//创建缩略图
   
   $config['source_image'] = $filenamePath;
   $config['thumb_marker'] = "_s";
   $config['image_library'] = 'gd2';
   $config['create_thumb'] = TRUE;  
   $config['maintain_ratio'] = FALSE;
   $config['width'] = $images_width;
   $config['height'] = $images_height;   
   
   $this->load->library('image_lib', $config);
   $this->image_lib->resize();  
  
   //加水印

   $config1['source_image'] = $filenamePath;  
   $config1['wm_type'] = 'overlay';
   $config1['wm_overlay_path'] = $_SERVER['DOCUMENT_ROOT'].'/images/watermark.gif';
   $config1['wm_vrt_alignment'] = 'bottom';
   $config1['wm_hor_alignment'] = 'right';
   $config1['wm_padding'] = '-50';
      $this->image_lib->initialize($config1);
      $this->image_lib->watermark();

同时使用的时候缩略图生成不了,而且水印加在新的图片上,我是想在原图上加水印,如果把其中一段注释掉,另外一段都能成功运行,也就是说把创建缩略图那段注释掉,加水印能成功;把加水印那段注释掉,创建缩略图能成功!请帮我看看是什么原因不能同时成功!  

发表于 2011-10-12 08:50:56 | 显示全部楼层

你创建完缩略图,filenamePath指向的图片已经有缩略图了,你再在这个缩略图上加水印。当然是你描述的那种情况了
你这相当于对一张图片做了两次操作。

你要想一张加水印,一张创建缩略图,你就得先复制一张原图出来。
 楼主| 发表于 2011-10-12 09:25:34 | 显示全部楼层
不是吧,例如filenamePath指向upload/1.jpg,生成的缩略图应该是upload/1_s.jpg,  filenamePath指向的不还是原来那个,怎么是在缩略图上加水印呢?
 楼主| 发表于 2011-10-12 09:29:02 | 显示全部楼层
弱弱的问一句,一张图片不能做两次操作吗?
 楼主| 发表于 2011-10-12 09:57:12 | 显示全部楼层
我复制了一个图操作还是不行,请教应该怎么操作,最好在我原来那个代码上修改一下
 楼主| 发表于 2011-10-12 19:27:09 | 显示全部楼层
没人说怎么搞吗?
发表于 2014-6-5 10:05:27 | 显示全部楼层
我也遇到这个问题!!!!!!!!!!!!
发表于 2014-6-5 13:20:10 | 显示全部楼层
水印 是在晚上照的 方法 没有用ci的,缩略图 是用的ci的
发表于 2014-6-5 13:22:22 | 显示全部楼层
打错字了,是网上
发表于 2014-6-5 13:23:10 | 显示全部楼层
//添加水印--文字
        function water_name($pic,$text,$pos=0){
                $dst_path = './'.$pic;
                $fontSize = 10;
                $pos = $pos==0?rand(1,9)pos;
                //创建图片的实例
                $dst = imagecreatefromstring(file_get_contents($dst_path));
                //打上文字
                $font    = './uploads/fangzheng.ttf';//字体
                $black   = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色
                $text_arr= $this->text_pos($text,$pos,$font,$fontSize,$pic);
                imagefttext($dst,$fontSize, 0, $text_arr[0],$text_arr[1], $black, $font,$text);

                //输出图片
                list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
                switch ($dst_type) {
                    case 1://GIF
                        header('Content-Type: image/gif');
                        imagegif($dst,$dst_path);
                        break;
                    case 2://JPG
                         header('Content-Type: image/jpeg');
                        imagejpeg($dst,$dst_path);
                        break;
                    case 3://PNG
                         header('Content-Type: image/png');
                        imagepng($dst,$dst_path);
                        break;
                    default:
                        break;
                }
         imagedestroy($dst);//销毁图片
        }

本版积分规则