图片加上水印的代码
能不能告诉我,图片加上水印的代码?谢谢了
(C#)给图片加上水印效果 private void Btn_Upload_Click(object sender, System。EventArgs e) { if(UploadFile。PostedFile。
FileName。Trim()!="") { //上传文件 string extension = Path。GetExtension(UploadFile。
PostedFile。FileName)。ToUpper(); string fileName = DateTime。Now。Year。ToString() + DateTime。Now。Month。ToString() + DateTime。
Now。Day。ToString() + DateTime。Now。Hour。ToString() + DateTime。Now。Minute。ToString() + DateTime。Now。Second。ToString(); string path = Server。
MapPath("。") + "/UploadFile/" + fileName + extension; UploadFile。PostedFile。SaveAs(path); //加文字水印,注意,这里的代码和以下加图片水印的代码不能共存 System。
Drawing。Image image = System。Drawing。Image。FromFile(path); Graphics g = Graphics。FromImage(image); g。
DrawImage(image, 0, 0, image。Width, image。Height); Font f = new Font("Verdana", 32); Brush b = new SolidBrush(Color。
White); string addText = AddText。Value。Trim(); g。DrawString(addText, f, b, 10, 10); g。
Dispose(); //加图片水印 System。Drawing。Image image = System。Drawing。Image。FromFile(path); System。
Drawing。Image copyImage = System。Drawing。Image。FromFile( Server。MapPath("。") + "/ f"); Graphics g = Graphics。
FromImage(image); g。DrawImage(copyImage, new Rectangle(image。Width-copyImage。Width, image。Height-copyImage。
Height, copyImage。Width, copyImage。Height), 0, 0, copyImage。Width, copyImage。Height, GraphicsUnit。Pixel); g。
Dispose(); //保存加水印过后的图片,删除原始图片 string newPath = Server。MapPath("。") + "/UploadFile/" + fileName + "_new" + extension; image。
Save(newPath); image。Dispose(); if(File。Exists(path)) { File。
Delete(path); } Response。Redirect(newPath); } } ----------------------------------------------------- PHP给图片加上水印效果 limit = 500;//长宽限制 $image->wm_text=" ";//水印文字 $image->wm_fontfile="font/ f";//字体文件 $image->wm_color="00cccc"; //$image->save_file = " g";//保存到xx文件 $image->create(" g");//从xx文件创建 /* +-------------------------------------------------------------------------- | 生成缩略图&加水印的图片类 | ============================ | by Dash | - 共享互联网 | ============================ | 网址: | 邮件:Dash@ +-------------------------------------------------------------------------- */ Class Gimage{ var $input_type = ""; //输入图片的格式 var $output_type = ""; //输出图片的格式 var $limit = 0; //图片大小限制 var $filename = ""; //输入图片的文件名(也可以直接是图片数据) var $jpeg_quality = 90; //jpeg图片质量 var $save_file = ''; //输出文件名 var $wm_text = ""; //水印文字( 不支持中文:'( ) var $wm_size = 50; //水印文字大小 var $wm_angle = 0; //水印文字角度 var $wm_x = 50; //水印x坐标 var $wm_y = 50; //水印y坐标 var $wm_color = "#cccccc"; //水印颜色 var $wm_fontfile = " f";//水印字体文件 function create($filename="") { if ($filename) $this->filename = $filename; if (!$this->input_type) $this->get_type(); if (!$this->output_type) $this->output_type = $this->input_type; if ($this->input_type == "jpg") $this->input_type = "jpeg"; if ($this->output_type == "jpg") $this->output_type = "jpeg"; switch ($this->input_type){ case 'gif': $src_img=ImageCreateFromGIF($this->filename); break; case 'jpeg': $src_img=ImageCreateFromJPEG($this->filename); break; case 'png': $src_img=ImageCreateFromPNG($this->filename); break; default: $src_img=ImageCreateFromString($this->filename); break; } $src_w=ImageSX($src_img); $src_h=ImageSY($src_img); if ($src_w>=$src_h){ if ($src_w>$this->limit){ $new_w=$this->limit; $new_h=($this->limit / $src_w)*$src_h; } } else{ if ($src_h>$this->limit){ $new_h=$this->limit; $new_w=($this->limit / $src_h)*$src_w; } } if ($new_h){ $dst_img=imagecreatetruecolor($new_w,$new_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img)); } else{ $dst_img = $src_img; } if ($this->wm_text) { if(preg_match("/([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i", $this->wm_color, $color)) { $red = hexdec($color[1]); $green = hexdec($color[2]); $blue = hexdec($color[3]); } $wm_color = imagecolorallocatealpha($dst_img, $red, $green, $blue, 90); imagettftext($dst_img, $this->wm_size, $this->wm_angle, $this->wm_x, $this->wm_y, $wm_color, $this->wm_fontfile, $this->wm_text); } if ($this->save_file) { switch ($this->output_type){ case 'gif': $src_img=ImagePNG($dst_img, $this->save_file); break; case 'jpeg': $src_img=ImageJPEG($dst_img, $this->save_file, $this->jpeg_quality); break; case 'png': $src_img=ImagePNG($dst_img, $this->save_file); break; default: $src_img=ImageJPEG($dst_img, $this->save_file, $this->jpeg_quality); break; } } else { header("Content-type: image/{$this->output_type}"); switch ($this->output_type){ case 'gif': $src_img=ImagePNG($dst_img); break; case 'jpeg': $src_img=ImageJPEG($dst_img, "", $this->jpeg_quality); break; case 'png': $src_img=ImagePNG($dst_img); break; default: $src_img=ImageJPEG($dst_img, "", $this->jpeg_quality); break; } } imagedestroy($dst_img); } function get_type()//获取图像文件类型 { $name_array = explode("。
",$this->filename); if (preg_match("/\。
(jpg|jpeg|gif|png)$/", $this->filename, $matches)) { $this->input_type = strtolower($matches[1]); } else { $this->input_type = "string"; } } } ?>。
用ASP为图片加水印 添加文字水印的方法: AddTxtMark 方法 AddTxtMark是在原图片上添加文字水印,并输出新的图片文件。 语法 AddTxtMark TargetFile, strText, TextColor, lTop, lLeft, nTxtOpacity, nShadeColor, nShadeOpacity, nShadeAngle, nShadeDistance , nShadeBlur TargetFile 返回新的图片文件的路径 strText 要添加的文字; TextColor 要添加的文字的颜色; lTop 要添加的文字在原图片上的顶边距; lLeft 要添加的文字在原图片上的左边距。
nTxtOpacity 文字透明度,范围0-100, 0-全透明 100-全不透明(缺省值),可选参数; nShadeColor 阴影颜色 缺省值为0,即黑色,可选参数; nShadeOpacity 阴影透明度 范围0-100, 0-全透明 100-全不透明(缺省值),可选参数; nShadeAngle 阴影角度 范围0-360,缺省值为45,即右下方向,可选参数; nShadeDistance 阴影距离 即阴影离文字的距离,缺省值为0,可选参数; nShadeBlur 阴影模糊距离 缺省值为0,即阴影没有渐进感,可选参数; 返回值: 1:成功 0:失败 Asp代码示例: 引用内容: "" then response。
write rorinfo end if ee set obj=nothing %> 添加图片水印方法: AddImgMark 方法 AddImgMark是在原图片上添加图片水印,并输出新的图片文件。 语法 AddImgMark TargetFile, lTop, lLeft, TransColor, Opacity where TargetFile 返回新的图片文件的路径; lTop 要添加的图片在原图片上的顶边距; lLeft 要添加的图片在原图片上的左边距; Opacity 水印的透明度。
Asp代码示例: 引用内容: "" then response。write rorinfo end if ee set obj=nothing %> 。
答:如果是男性,二三十岁,每天想做爱,这是正常的,身体很强壮,荷尔蒙分泌很旺盛,这是很正常的,但是什么事情都有个度,每天想做,这是你的需求,但是如果你确实在做,这样...详情>>
答:即墨蒙娜丽莎详情>>
问:我想买一只数码相机,请问什么样品牌的相机好,一般家庭用家价格多少合适
答:个人比较喜欢sony的 三千多巴详情>>