Add a watermark to a picture
Copy Code code as follows:
<%
Dim Jpeg ""//Declaration variable
Set Jpeg = Server.CreateObject ("Persits.jpeg") ""//Calling Component
Jpeg.open Server.MapPath ("AAA"). JPG ")"//Source Picture position
Jpeg.Canvas.Font.Color = &h000000 ""//Watermark Font Color
Jpeg.Canvas.Font.Family = "Song Body" ""//Watermark Font
Jpeg.Canvas.Font.Size = 14 ""//Watermark Font Size
Jpeg.Canvas.Font.Bold = False ""//Bold, Bold: True
Jpeg.Canvas.Font.BkMode = &HFFFFFF ""//font background color
Jpeg.Canvas.Print 10, 10, "unbeaten studio" ""///Watermark text, two digit 10 xy coordinates for Watermark
Jpeg.save Server.MapPath ("aaa_05.jpg") ""//Create new image with watermark and save location
Set Jpeg = Nothing ""//Logoff component, releasing resources
Response.Write "%>
Second, generate thumbnails
Copy Code code as follows:
<%
Dim Jpeg ""//Declaration variable
Set Jpeg = Server.CreateObject ("Persits.jpeg") ""//Calling Component
Jpeg.open Server.MapPath ("AAA"). JPG ")" "//Original position
Jpeg.width = JPEG.ORIGINALWIDTH/4 ""//Set picture width to One-fourth of the original image
Jpeg.height = JPEG.ORIGINALHEIGHT/4 ""//Set picture height to One-fourth of original artwork
Jpeg.sharpen 1, 130 ""//Set Sharpening effect
Jpeg.save Server.MapPath ("aaa_small.jpg") ""//Generate thumbnail location and name
Set Jpeg = Nothing ""//Logoff component, releasing resources
Response.Write "%>
[Code]
Introduction to advanced usage of ASPJPEG components
AspJpeg is a very powerful image processing component, a pure English version. However, there has been a free version and cracked version, but the detailed and in-depth introduction of the article is not much, even if there is only a picture of the thumbnail and image watermark. Maybe it's because of pure English.
This is where I talk about the advanced usage of aspjpeg. The main technologies here include:
Thumbnail image
Picture watermark
Security Code Technology
Picture Cutting
Picture Merge
Database support
More less frequently Used method introduction
And some of the relevant practical techniques
AspJpeg the only point is that the output mode is relatively single. Here, we mainly talk about how to save the image processing and then call this output method. In addition, I am lazy, so some code is still quoted in the original file, do not understand the place I will explain!
The comrade who has studied VB or. NET must see it clearly. Brush again. Oh.
One, the picture is abbreviated
[Code]
<%
Set Jpeg = Server.CreateObject ("Persits.jpeg") Invoke component
Path = Server.MapPath ("Images") & "\clock.jpg" Picture path to process
Jpeg.open Path Open Picture
High and wide for the original picture of 1/2
Jpeg.width = JPEG.ORIGINALWIDTH/2
Jpeg.height = JPEG.ORIGINALHEIGHT/2
Save picture
Jpeg.save Server.MapPath ("Images") & "\clock_small.jpg"
%>
[Code]
View processed Pictures
Second, picture watermark
[Code]
<%
Set Jpeg = Server.CreateObject ("Persits.jpeg")
Jpeg.open Server.MapPath ("Images/dodge_viper.jpg")
Start writing text
Jpeg.Canvas.Font.Color = &h000000 "" White color
Jpeg.Canvas.Font.Family = "Courier New" font
Jpeg.Canvas.Font.Bold = True is bold
Jpeg.Canvas.Print, "Copyright (c) XYZ, Inc."
Print coordinates x print coordinates y the characters you need to print
The following is a border treatment of a picture
Jpeg.Canvas.Pen.Color = &h000000 "" Black color
Jpeg.Canvas.Pen.Width = 2 Brush width
Jpeg.Canvas.Brush.Solid = False is bold processing
Jpeg.Canvas.Bar 1, 1, jpeg.width, jpeg.height
Start x coordinate start y coordinate input length input height
Jpeg.save Server.MapPath ("images/dodge_viper_framed.jpg") Save
%>
Third, security code
Safe Ma Truth and add watermark almost, a lot of friends asked me to specific code technology, here I write to share with you, ordinary people I do not tell him. Oh.
Copy Code code as follows:
<%
A function that generates a security code
function Make_randomize (max_len,w_n) Max_len build length, w_n:0 may contain letters, 1: Only for numbers
Randomize
For Intcounter=1 to Max_len
Whatnext=int ((1-0+1) *rnd+w_n)
If Whatnext=0 Then
upper=122
lower=97
Else
upper=57
lower=48
End If
Strnewpass=strnewpass & Chr (int ((upper-lower+1) *rnd) +lower)
Next
Make_randomize=strnewpass
End Function
%>
A picture that generates a security code. Of course, you have to prepare a background picture beforehand.
Copy Code code as follows:
<%random_num=make_randomize (4,1) generates a 4-digit security Code
Session ("Random_num") =random_num why call session, no session of the security code is completely meaningless. Oh
Set Jpeg = Server.CreateObject ("Persits.jpeg") Invoke component
Jpeg.open Server.MapPath ("Infos/random_pic/random_index.gif") open the prepared picture
Jpeg.Canvas.Font.Color = &h006699
Jpeg.Canvas.Font.Family = "Arial Black"
Jpeg.Canvas.Font.Bold = False
Jpeg.Canvas.PrintText 0,-2, Random_num
Jpeg.save Server.MapPath ("Infos/random_pic/random_index.bmp") Save
%>
Do it yourself. Oh.
Four, picture cutting
For a long time, people who don't know aspjpeg think they can't use it for cutting.
In fact there is such a method of
Crop X1,y1,x2,y2
Cut rectangular type upper left corner x coordinate, y coordinate x coordinate y coordinate
I'm going to do a demo right now, huh?
Set Jpeg = Server.CreateObject ("Persits.jpeg")
Jpeg.open server. MapPath ("/pic/1.gif")
Jpeg.width=70
Jpeg.height = Jpeg.originalheight*70/jpeg. Originawidth
Jpeg.crop 0,0,70,52 Start Cutting is actually removing the lower part of more than 52 pixels.
Jpeg.save server. MapPath ("/temp_pic/small_1.gif") Save
Well, it's easy.
V. Picture merging
We're here to add the logo picture to the dodge_viper.jpg picture.
In fact, the image of the combination of methods can also be used to dynamic water printing OH
Copy Code code as follows:
Set Photo = Server.CreateObject ("Persits.jpeg")
Photopath = Server.MapPath ("Images") & "\dodge_viper.jpg"
Photo.open Photopath
Set Logo = Server.CreateObject ("Persits.jpeg")
Logopath = Server.MapPath ("Images") & "\clock.jpg"
Logo.open Logopath
Logo.width = 70
Logo.height = Logo.width * logo.originalheight/logo.originalwidth
Photo.drawimage 0, 0, Logo
Photo.sendbinary uses the Sendbinary output method here. Of course, you can also save the changed dodge_viper.jpg first, and then enter it. I personally do not like using the Sendbinary method, when the speed is slow, error prone. Not so in terms of speed. Oh.
Vi. Database Support
There's not much to say here. In fact, is the binary method, we know that the image stored in the database can only be stored as binary files. So the code is lazy to write.
Vii. more ways of introducing
Copy Code code as follows:
Canvas.line (left, top, right, Bottom)
Draw a straight line
Canvas.ellipse (left, top, right, Bottom)
Draw an Ellipse
Canvas.circle (X, Y, Radius)
Draw a Circle
Canvas.bar (left, top, right, Bottom)
Draw a rectangle with code that describes the
Canvas.Font.ShadowColor
Text Shadow Color
Canvas.Font.ShadowXOffset as Long
Shadow X coordinate set
Canvas.Font.ShadowYOffset as Long
Y-coordinate setting
Canvas.Font.BkMode as String
Text background
========================================
Today, we are talking about the ASP to the picture watermark knowledge
ASP to add watermark to the image is the need for components ... Commonly used by AspJpeg and the Chinese developed their own wsimage ... The former has 30 days of free ... The latter is completely free ... Of course we have to use the products of our countrymen. Hey..
How to register a component:
At the command prompt, enter "regsvr32 [DLL path]".
Image add watermark is simply to get the picture size, and then write the watermark up. The ASP code is just a control component. Use code to explain everything.
One: Get the picture size (here is the pixel value). All the friends who are learning Photoshop should understand.
Copy Code code as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize") "" "" "to invoke the component
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "to open the picture, the picture name is 25.jpg
Obj. Getsourceinfo Iwidth,iheight
Response.Write "Picture width:" & iwidth & "" "" "Get Picture width
Response.Write "Picture height:" & iheight & "" "" "Get picture height
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>
Two: Add text watermark
Copy Code code as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "" "Load picture
Obj. Quality=75
Obj. Txtmarkfont = "Chinese Cloud" "" "Set watermark text font
Obj. Txtmarkbond = False "" To set the thickness of the watermark text
Obj. markrotate = 0 "" "" "the angle of rotation of the watermark text
Obj. Txtmarkheight = 25 "" "" "the height of the watermark text
Obj. Addtxtmark Server.MapPath ("txtmark.jpg"), "take you out of the departure", &h00ff00& 10, 70
Strerror=obj.errorinfo "" "" "produces the name of the picture, the text color is the watermark in the picture position
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>
Three: Add a picture watermark
Copy Code code as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "" "Load picture
Obj. Loadimgmarkpic Server.MapPath ("blend.bmp") "" "Load watermark Picture
Obj. Quality=75
Obj. Addimgmark Server.MapPath ("imgmark.jpg"), 315, 220,&HFFFFFF, 70
Strerror=obj.errorinfo "" "" "produces the name of the picture, the text color is the watermark in the picture position
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>
In fact, add a watermark to the picture is so simple. And then I'm going to say another two main usages of the WsImage.dll component. Includes:
Trim the picture and generate a thumbnail of the picture.
Or in my habit, use code to add notes:
To trim a picture:
Copy Code code as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg")
Obj. Quality=75
Obj.cropimage Server.MapPath ("25_crop.jpg"), 100,10,200,200 "" "" "to define cut size and generate picture names
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>
Detailed note: Cut the picture to use the Wsimage Cropimage method. When the definition generates the picture, 100,10 is the cut point in the upper left corner, which is 100 pixels to the left of the picture, and the top 10 pixels. The latter two 200 represent the cut of the broadband and high and height.
To generate a thumbnail image of a picture:
Copy Code code as follows:
<%
Set Obj=server. CreateObject ("Wsimage.resize")
Obj. Loadsoucepic Server.MapPath ("25.jpg") "" "Load picture
Obj. Quality=75
Obj. Outputspic Server.MapPath ("25_s.jpg"), 0.5,0.5,3 "" "to define the name of the thumbnail is the size
Strerror=obj.errorinfo
If strerror<> "" Then
Response.Write Obj.errorinfo
End If
Obj.free
Set obj=nothing
%>
Detailed Description:
There are four ways to export a thumbnail:
(1) obj. Outputspic Server.MapPath ("25_s.jpg"), 200,150,0
200 for the output width, 150 for the output is high, this type of output is forced output width high, may cause picture distortion.
(2) obj. Outputspic Server.MapPath ("25_s.jpg"), 200,0,1
With 200 as the output width, the output height will scale with the column.
(3) obj. Outputspic Server.MapPath ("25_s.jpg"), 0,200,2
Output is high with 200, and the output width will scale with the column.
(4) obj. Outputspic Server.MapPath ("25_s.jpg"), 0.5,0.5,3
The first 0.5 indicates that the resulting thumbnail is half the width of the original image, which means a narrowing ratio.
The second 0.5 means that the resulting thumbnail is half the height of the original image, which means a high narrowing ratio.
A wide-height narrowing of the proportions means that the original image will be scaled down. If the zoom ratio is greater than 1, the original image is magnified.
Last night to get 12:30, get up in the morning to continue to enhance optimization, wrote this ASP batch Watermark tool, this watermark effect is my dream has been long, very cool!
The watermark effect is as follows: