其实打水印是在我们前台页面控制的。
注意我们标红字段:
//初始化编辑器
var editor = KindEditor.create('.editor', {
width: '100%',
height: '350px',
filterMode: false, //默认不过滤HTML
resizeType: 1,
uploadJson: '/tools/upload_ajax.ashx?action=EditorFile&IsWater=0',
fileManagerJson: '/tools/upload_ajax.ashx?action=ManagerFile',
allowFileManager: true
});
uploadJson: '/tools/upload_ajax.ashx?action=EditorFile&IsWater=0', 注意:IsWater=0表示不打水印 IsWater=1表示打水印
//初始化上传控件
$(".upload-img").InitUploaderOld({ filesize: "102400", sendurl: "/tools/upload_ajax.ashx", swf: "/scripts/webuploader/uploader.swf", filetypes: "gif,jpg,png,bmp" });
$(".upload-video").InitUploader({ filesize: "102400", sendurl: "/tools/upload_ajax.ashx", swf: "/scripts/webuploader/uploader.swf", filetypes: "flv,mp3,mp4,avi" });
$(".upload-album").InitUploaderOld({ btntext: "批量上传", multiple: true, water: true, thumbnail: true, filesize: "30720", sendurl: "/tools/upload_ajax.ashx", swf: "/scripts/webuploader/uploader.swf" });
$(".upload-album").InitUploaderOld({ btntext: "批量上传", multiple: true, water: true, thumbnail: true, filesize: "30720", sendurl: "/tools/upload_ajax.ashx", swf: "/scripts/webuploader/uploader.swf" });
注意:water:true 表示打水印。如果不填或者为false 表示不打水印
后台打水印实现方法:
/// <summary>
/// 文件上传方法
/// </summary>
/// <param name="postedFile">文件流</param>
/// <param name="isThumbnail">是否生成缩略图</param>
/// <param name="isWater">是否打水印</param>
/// <returns>上传后文件信息</returns>
public string fileSaveAs(HttpPostedFile postedFile, bool isThumbnail, bool isWater,string type="")
{
try
{
string fileExt = Utils.GetFileExt(postedFile.FileName); //文件扩展名,不含“.”
int fileSize = postedFile.ContentLength; //获得文件大小,以字节为单位
string fileName = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(@"\") + 1); //取得原文件名
string newFileName = Utils.GetRamCode() + "." + fileExt; //随机生成新的文件名
string newThumbnailFileName = "thumb_" + newFileName; //随机生成缩略图文件名
string upLoadPath = GetUpLoadPath(); //上传目录相对路径
string fullUpLoadPath = Utils.GetMapPath(upLoadPath); //上传目录的物理路径
string newFilePath = upLoadPath + newFileName; //上传后的路径
string newThumbnailPath = upLoadPath + newThumbnailFileName; //上传后的缩略图路径
//检查文件扩展名是否合法
if (!CheckFileExt(fileExt))
{
return "{\"status\": 0, \"msg\": \"不允许上传" + fileExt + "类型的文件!\"}";
}
//检查文件大小是否合法
if (!CheckFileSize(fileExt, fileSize))
{
return "{\"status\": 0, \"msg\": \"文件超过限制的大小啦!\"}";
}
//检查上传的物理路径是否存在,不存在则创建
if (!Directory.Exists(fullUpLoadPath))
{
Directory.CreateDirectory(fullUpLoadPath);
}
//保存文件
postedFile.SaveAs(fullUpLoadPath + newFileName);
//如果是图片,检查图片是否超出最大尺寸,是则裁剪
//新增判断是否是编辑器图片s
if (type=="editor")
{
if (IsImage(fileExt) && (this.siteConfig.editorimgheight > 0 || this.siteConfig.editorimgwidth > 0))
{
Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newFileName,
this.siteConfig.editorimgwidth, this.siteConfig.editorimgheight);
}
}
else
{
if (IsImage(fileExt) && (this.siteConfig.imgmaxheight > 0 || this.siteConfig.imgmaxwidth > 0))
{
Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newFileName,
this.siteConfig.imgmaxwidth, this.siteConfig.imgmaxheight);
}
}
//新增判断是否是编辑器图片e
//如果是图片,检查是否需要生成缩略图,是则生成
if (IsImage(fileExt) && isThumbnail && this.siteConfig.thumbnailwidth > 0 && this.siteConfig.thumbnailheight > 0)
{
Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newThumbnailFileName,
this.siteConfig.thumbnailwidth, this.siteConfig.thumbnailheight, "Cut");
}
//如果是图片,检查是否需要打水印 如果要打水印传入值是 true
if (IsWaterMark(fileExt) && isWater)
{
switch (this.siteConfig.watermarktype) //水印模式1为文字。2为图片 {
case 1:
WaterMark.AddImageSignText(newFilePath, newFilePath,
this.siteConfig.watermarktext, this.siteConfig.watermarkposition,
this.siteConfig.watermarkimgquality, this.siteConfig.watermarkfont, this.siteConfig.watermarkfontsize);
break;
case 2:
WaterMark.AddImageSignPic(newFilePath, newFilePath,
this.siteConfig.watermarkpic, this.siteConfig.watermarkposition,
this.siteConfig.watermarkimgquality, this.siteConfig.watermarktransparency);
break;
}
}
//处理完毕,返回JOSN格式的文件信息
return "{\"status\": 1, \"msg\": \"上传文件成功!\", \"name\": \""
+ fileName + "\", \"path\": \"" + newFilePath + "\", \"thumb\": \""
+ newThumbnailPath + "\", \"size\": " + fileSize + ", \"ext\": \"" + fileExt + "\"}";
}
catch
{
return "{\"status\": 0, \"msg\": \"上传过程中发生意外错误!\"}";
}
}
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4