一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp.net FCKeditor上传图片加入水印代码

时间:2010-08-29 编辑:简简单单 来源:一聚教程网

如何在自己的网站中架设fckeditor编辑器我就不说了,本文默认你已经架设过并且熟悉fckeditor内部结构。
在下载fckeditor编辑器的同时,如果是使用.net版本,还必须下载一个源代码包,在里面有一些功能类,和编译出来的dll文件,存放在bin文件中,我们所需要做的就是修改源代码,获得新的dll,在自己的网站中替换就可以了。
(源代码版本号是fckeditor.net_2.5,编辑器文件版本号为fckeditor_2.6.2)
实用vs2005打开代码包根目录下的fredck.fckeditorv2.vs2005.csproj文件,待文件树展开后,找到filebrowser文件夹下的fileworkerbase.cs文件,对其进行修改。
我们需要的是修改fileworkerbase类中的fileupload方法函数。
在看代码之前先简单的介绍一下我的想法。我在自己的网站中建立了general.config文件,用于存放网站的一些配置信息,如水印的类型(文字型,图片型),是否需要加水印,文字型水印的文字内容等等和本文无关的重要配置信息。所以在如下带代码中,有一段是用来读取这些配置信息的。
在fileupload方法中找到ofile.saveas( sfilepath );语句

try
{
     dataset configds = new dataset();
     configds.readxml(server.mappath("~/config/general.config"));
     datatable configdt = configds.tables[0];
     if (configdt.rows[0]["watermarkstatus"].tostring() == "1")
     {
         image img = image.fromfile(sfilepath);
         if (configdt.rows[0]["watermarktype"].tostring() == "0")
         {
             graphics g = graphics.fromimage(img);
             g.drawimage(img, 0, 0, img.width, img.height);
             font f = new font("华文行楷", 40);
             brush b = new solidbrush(color.white);
             string addtext = configdt.rows[0]["watermarktext"].tostring();
             g.drawstring(addtext, f, b, img.width - 174, img.height - 40);
             g.dispose();
         }
         if (configdt.rows[0]["watermarktype"].tostring() == "1")
         {
             system.drawing.image copyimage = system.drawing.image.fromfile(server.mappath("~/watermark/watermark.gif"));
             graphics g = graphics.fromimage(img);
             g.drawimage(copyimage, new rectangle(img.width - copyimage.width, img.height - copyimage.height, copyimage.width, copyimage.height), 0, 0, copyimage.width, copyimage.height, graphicsunit.pixel);
             g.dispose();
         }
         sfilename = system.io.path.getfilenamewithoutextension(ofile.filename);
           string newpath = sfilename+"_"+datetime.now.tostring("yymmddhhmmss") + "." + sextension;
           newpath = system.io.path.combine(sserverdir, newpath);
           sfilename = newpath;
           img.save(newpath);
           img.dispose();
          if (file.exists(sfilepath))
          {
               file.delete(sfilepath);
          }
       }
     }
catch
{
      this.sendfileuploadresponse(808, isquickupload);
}

热门栏目