asp.net fckeditor upload image add watermark code

Source: Internet
Author: User

How to set up FCKeditor editor in your own website I do not say, this article by default you have been erected and familiar with fckeditor internal structure.
While downloading the FCKeditor editor, if you are using the. NET version, you must also download a source code package, where there are functional classes, and compiled DLL files, stored in the bin file, all we need to do is modify the source code, get the new DLL, Replace it on your own website.
(Source code version number is fckeditor.net_2.5, editor file version number is fckeditor_2.6.2)
Utility VS2005 Open the Fredck.fckeditorv2.vs2005.csproj file in the code package root directory, and after the file tree is expanded, locate the Fileworkerbase.cs file under the Filebrowser folder and modify it.
What we need is to modify the FileUpload method function in the Fileworkerbase class.
Before looking at the code, let me briefly introduce my thoughts. I set up a general.config file in my own website, used to store some configuration information of the website, such as the type of watermark (text type, picture type), whether need watermark, text watermark text content and so on and important configuration information irrelevant to this article. So in the following code, a section is used to read the configuration information.
Find Ofile.saveas (Sfilepath) in the FileUpload method;

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 ("XXFarEastFont-Xingkai", 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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.