The following describes how to create a batch watermark Tool Based on aspjpeg.

Source: Internet
Author: User
Tags watermark images

1. Add watermarks to images CopyCode The Code is as follows: <%
Dim jpeg "" // declare the variable
Set JPEG = server. Createobject ("persits. JPEG") "// call the component
JPEG. Open Server. mappath ("AAA. jpg") "// source Image Location
JPEG. Canvas. Font. Color = & h000000 "// watermark font color
JPEG. Canvas. Font. Family = "" "// watermark font
JPEG. Canvas. Font. size = 14 "// watermark font size
JPEG. Canvas. Font. Bold = false "// specifies whether the image is in bold or not. Use true in bold.
JPEG. Canvas. Font. bkmode = & hffffff "// font background color
JPEG. Canvas. Print 10, 10, "unbeaten urchin Studio" "// watermark text. Two numbers 10 are the XY coordinates of the watermark.
JPEG. Save server.mappath(“aaa_05.jpg ")" // generate a new image with a watermark and its storage location
Set JPEG = nothing "// deregister the component and release the resource
Response. Write "%>

Ii. Generating thumbnails Copy code The Code is as follows: <%
Dim jpeg "" // declare the variable
Set JPEG = server. Createobject ("persits. JPEG") "// call the component
JPEG. Open Server. mappath ("AAA. jpg") "// source Image Position
JPEG. width = jpeg. originalwidth/4 "// set the image width to 1/4 of the source image width.
JPEG. Height = jpeg. originalheight/4 "// set the Image Height to 1/4 of the source Image Height.
JPEG. Sharpen 1,130 "// sets the sharpening Effect
JPEG. Save server.mappath(“aaa_small.jpg ")" // generates the thumbnail position and name
Set JPEG = nothing "// deregister the component and release the resource
Response. Write "%>
[Code]
Advanced usage of the aspjpeg component
Aspjpeg is a powerful image processing component in English only. However, the free and cracked versions have already been available, but they are described in detail and in depth. Article However, there are not many, even if there are, only image scaling and image watermarks are involved. It may be because it is only English.
Here I will talk about the advanced usage of aspjpeg to address these issues. The technologies here mainly include:
Thumbnail
Image Watermark
Security code technology
Image Cutting
Image Merging
Database Support
More uncommon Methods
And some related practical technologies
The only disadvantage of aspjpeg is that the output mode is relatively simple. Here, we mainly talk about the output method that is called after image processing is saved. In addition, I am relatively lazy, so some code is still referenced in the original document. I will explain it even if I don't understand it!
Comrades who have studied VB or. NET must have understood it at a glance. Brush. Haha.
I. scaling down images
[Code]
<%
Set JPEG = server. Createobject ("persits. JPEG") Call the component
Path = server. mappath ("images") & "\ clock.jpg"
JPEG. Open Path
The height and width are 1/2 of the original image.
JPEG. width = jpeg. originalwidth/2
JPEG. Height = jpeg. originalheight/2
Save image
JPEG. Save server. mappath ("images") & "\ clock_small.jpg"
%>
[Code]
View the processed image
Ii. Image 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 bold or not
JPEG. Canvas. Print 10, 10, "Copyright (c) XYZ, Inc ."
Print coordinates x print coordinates y print characters
The following is the border processing for the image
JPEG. Canvas. Pen. Color = & h000000 "black color
JPEG. Canvas. Pen. width = 2 paint width
JPEG. Canvas. Brush. Solid = false whether to perform 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
%>

3. Security Code
The principle of security Ma is similar to watermarking. Many friends asked me to ask for specific code technologies. Here I will share it with you. I will not tell anyone else. Haha.Copy codeThe Code is as follows: <%
Functions for generating security codes
Function make_randomize (max_len, w_n) max_len generation length. w_n: 0 may contain letters. 1: only 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
%>

Generate an image with a security code. Of course, you need to prepare a background image in advance. copy Code the code is as follows: <% random_num = make_randomize) generate a four-digit security code
SESSION ("random_num") = Why does random_num call the session? the security code without the session is meaningless. Haha
set JPEG = server. createobject ("persits. JPEG ") Call the component
JPEG. open Server. mappath ("Infos/random_pic/random_index.gif") Open the prepared image
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. Haha.
4. Image cutting
for a long time, people who do not know about aspjpeg think that they cannot use it for cutting.
In fact, there is such a method
crop X1, Y1, X2, Y2
cut the X coordinate in the upper left corner of the rectangular shape, in the lower right corner of Y coordinate, the X coordinate Y coordinate
below is a demonstration.
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 is actually to remove the lower part of more than 52 pixels
JPEG. save server. mappath ("/temp_pic/small_1.gif") Save
easy to save
5. Merge images
here we want to add the logoimage to the dodge_viper.jpg image.
actually, the image merging method can also be used to dynamically watermark images. copy Code the code is 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 the output method of sendbinary is used here. Of course, you can save and modify the dodge_viper.jpg file, and then enter it. I personally do not like to use the sendbinary method, which is prone to errors when the network speed is slow. The speed is not very good. Haha.
6. Database Support
I will not talk about it here. It is actually the binary method. We know that images can only be saved as binary files in the database. So the code is too lazy to write.
7. More methods copy Code the code is as follows: canvas. line (left, top, right, bottom)
draw a straight line
canvas. ellipse (left, top, right, bottom)
draws an ellipse
canvas. circle (X, Y, radius)
draw a circle
canvas. bar (left, top, right, bottom)
draws a rectangle with the code described above
canvas. font. shadowcolor
text shadow color
canvas. font. shadowxoffset as long
Shadow X coordinate setting
canvas. font. shadowyoffset as long
Y coordinate setting
canvas. font. bkmode as string
text background

================================================= ===< br> today I want to talk about ASP's knowledge of watermarking images.
Asp needs components to add watermarks to images... Common examples include aspjpeg and wsimage developed by the Chinese... The former has 30 days of free... The latter is completely free... Of course we will use Chinese products .. hey hey ..
method of registering a component:
enter "regsvr32 [dll path]" at the command prompt.
adding a watermark to an image is nothing more than obtaining the image size, then write the watermark .. ASP code is only a control component. use code to describe everything.
1. Obtain the image size (represented in pixels. all friends who learn Photoshop should understand) copy Code the code is as follows: <%
set OBJ = server. createobject ("wsimage. resize ")" call component
obj. loadsoucepic server.mappath(%25.jpg ") when you open the image, the image name is 25.jpg
obj. getsourceinfo iwidth, iheight
response. write "Image Width:" & iwidth & "
" to get the image width
response. write "Image Height:" & iheight & "
" to get the image height
strerror = obj. errorinfo
If strerror <> "" Then
response. write obj. errorinfo
end if
obj. free
set OBJ = nothing
%>

2: Add a text watermark copy Code the code is as follows: <%
set OBJ = server. createobject ("wsimage. resize ")
obj. loadsoucepic server.mappath(%25.jpg ")" load image
obj. quality = 75
obj. txtmarkfont = "文" sets the watermark text font
obj. txtmarkbond = false "sets the watermark text width
obj. markrotate = 0 "watermark text Rotation Angle
obj. txtmarkheight = 25 "watermark text height
obj. addtxtmark server.mappath(“txtmark.jpg ")," Take you away ", & h00ff00 &, 10, 70
strerror = obj. errorinfo "to generate the image name. The text color is the position of the watermark in the image
If strerror <>" "then
response. write obj. errorinfo
end if
obj. free
set OBJ = nothing
%>

3: add an image watermark copy Code the code is as follows: <%
set OBJ = server. createobject ("wsimage. resize ")
obj. loadsoucepic server.mappath(%25.jpg ")" load image
obj. loadimgmarkpic server.mappath(“blend.bmp ")" load watermark image
obj. quality = 75
obj. addimgmark server.mappath(“imgmark.jpg "), 315,220, & hffffff, 70
strerror = obj. errorinfo "to generate the image name. The text color is the position of the watermark in the image
If strerror <>" "then
response. write obj. errorinfo
end if
obj. free
set OBJ = nothing
%>

adding a watermark to an image is as simple as that. then I'm talking about wsimage. the other two main usage of the DLL component. including:
crop an image to generate a thumbnail of the image.
as I used to it, I used the code to add comments:
image cropping: copy Code the code is as follows: <%
set OBJ = server. createobject ("wsimage. resize ")
obj. loadsoucepic server.mappath(%25.jpg ")
obj. quality = 75
obj. cropimage server.mappath(%25_crop.jpg "), 200,200, 10," defines the cut size and the name of the generated image
strerror = obj. errorinfo
If strerror <> "" Then
response. write obj. errorinfo
end if
obj. free
set OBJ = nothing
%>

Note: The cropimage method of wsimage is used for image cropping. when an image is generated, 100 and 10 are the cut points in the upper left corner, that is, pixels on the left and 10 pixels on the top. the last two 200 represents the cut bandwidth and height.
image thumbnails: copy Code the code is as follows: <%
set OBJ = server. createobject ("wsimage. resize ")
obj. loadsoucepic server.mappath(%25.jpg ")" load image
obj. quality = 75
obj. outputspic server.mappath(%25_s.jpg "), 0.5, 0.5, 3" defines the thumbnail name as 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 is the output width and 150 is the output height. This output form is forced output width and height, which may cause image deformation.
(2) obj. outputspic server.mappath(%25_s.jpg "), 0, 1
The output width is 200, and the output height scales with the ratio column.
(3) obj. outputspic server.mappath(%25_s.jpg "), 0,200, 2
The output height is 200, and the output width scales with the ratio column.
(4) obj. outputspic server.mappath(%25_s.jpg "), 0.5, 0.5, 3
The first 0.5 indicates that the generated thumbnail is half the width of the source image, that is, the width reduction ratio.
The second 0.5 indicates that the generated thumbnail is half the height of the source image, that is, the scaled down ratio is high.
The scaled-down ratio of the width and height is the same, which means that the ratio of the source image is reduced. If the zoom ratio is greater than 1, the source image is enlarged.
I got a video at last night and got up in the morning to continue enhancement and optimization. I wrote this ASP batch watermark tool. This watermark effect has been very good for me for a long time!

The watermark effect is as follows:

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.