asp.net FCKeditor上傳圖片加入浮水印代碼

來源:互聯網
上載者:User

如何在自己的網站中架設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);
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.