Implement simple text watermark with ASP.

Source: Internet
Author: User

Often see the mop on the person posted that dynamic picture, that is, a string as a parameter to a Dynamic Web page, will generate a picture with this string, this is called a text watermark. Like what the original Panda series, as well as the later trees and gold bars, are very interesting. I wrote a very simple one with ASP. The entire code is as follows:

<%@ Import namespace= "System"%>
<%@ Import Namespace= "System.IO"%>
<%@ Import namespace= "System.Drawing"%>

<%@ page language= "VB"%>

<script runat= "Server" >
Dim FilePath as String = Server.MapPath ("talk.jpg")

Sub Page_Load (Sender as Object, E as EventArgs)
Dim image as System.Drawing.Image = System.Drawing.Image.FromFile (FilePath)
Dim g as Graphics = graphics.fromimage (image)
G.drawimage (image, 0, 0, image. Width, image. Height)
Dim f as Font = new Font ("XXFarEastFont-Xingkai", 40)
Dim B as Brush = new SolidBrush (color.black)
Dim s as String = Left (Request.QueryString ("str"), 7)
g.DrawString (S, F, B, 20, 190)
Image. Save (Response.outputstream, System.Drawing.Imaging.ImageFormat.Jpeg)
G.dispose ()
Image. Dispose ()
End Sub
</script>

Just save this code as an ASPX file, such as Test.aspx. Then put it in the wwwroot (assuming your virtual directory is the default). Then make a talk.jpg picture, you can print the "Chinese Xingkai" in this place (20, 190) The text of the font. The invocation method is simple:

Http://localhost/Test.aspx?str= Test for a moment!

You can set the print location and font as well as the picture file. In addition, if an E is displayed as a parameter, and for Chinese, it is because the Web. config setting is incorrect, the following settings are required:

<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<system.web>
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
</system.web>
</configuration>

This way, it can be displayed normally.

Implement simple text watermark with ASP.

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.