ASP Component aspjpeg (watermarking)

Source: Internet
Author: User
<%
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. Use true in bold.

JPEG. Canvas. Font. bkmode = & hffffff''' // font background color

JPEG. Canvas. Print 10, 10, "www.data-bin.cn" ''' // watermark text, two digits 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 "" ''' // The watermark image is displayed on this page.
%>

Ii. Generating thumbnails

<%
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 "" ''' // The generated thumbnail is displayed on this page.
%>

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.ArticleHowever, 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 someCodeIt is still referenced in the original document and will be explained occasionally if you do not understand it!

Comrades who have studied VB or. NET must have understood it at a glance. Brush. Haha.

I. scaling down images

<%
Set JPEG = server. Createobject ("persits. jpeg") Call the component
Path = server. mappath ("Images") & "\ clock.jpg" Path of the image to be processed
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"
%>
View processed images

Ii. Image Watermark

<%
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.

<%
Function for generating security codes: www.wuyouw.com
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 a picture of the security code. Of course, you need to prepare a background image in advance.

<% Random_num = make_randomize () generates 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.

Iv. 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
Returns the X coordinate in the upper left corner of the rectangular shape, and the Y coordinate in the lower right corner of the Y coordinate.
Here 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, start to cut is actually to remove the lower part of more than 52 pixels
JPEG. Save server. mappath ("/temp_pic/small_1.gif") Save
How is it? It's easy.

5. Image Merging

We need to add the logoimage to the dodge_viper.jpg image.
In fact, the image merging method can also be used for dynamic watermarking.
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.

Vi. 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

Canvas. Line (left, top, right, bottom)
Draw a straight line
Canvas. ellipse (left, top, right, bottom)
Draw an elliptic
Canvas. Circle (X, Y, radius)
Draw a circle
Canvas. Bar (left, top, right, bottom)
Draw a rectangle with code on it.
Canvas. Font. shadowcolor
Text shadow color
Canvas. Font. shadowxoffset as long
Shadow X coordinate settings
Canvas. Font. shadowyoffset as long
Y coordinate settings
Canvas. Font. bkmode as string
Text background

==========================================================

Today, I want to talk about ASP's knowledge of watermarking images.

Adding watermarks to Images Using ASP requires components... common examples include aspjpeg and wsimage developed by the Chinese... the former has 30 days of free... the latter is free of charge... of course we will use Chinese products .. hey hey ..

Method for 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, and then writing the watermark. ASP code is just a control component. Use code to describe everything.

I. Obtain the image size (represented in pixels here. All the friends who learn Photoshop should understand)
<%
Set OBJ = server. Createobject ("wsimage. Resize") ''' call the component
OBJ. loadsoucepic server. mappath ("25.jpg") ''''''open the image. The image name is 25.jpg.
OBJ. getsourceinfo iwidth, iheight
Response. Write "Image Width:" & iwidth &"
"''' Get the image width.
Response. Write "Image Height:" & iheight &"
"''' Get the Image Height
Strerror = obj. errorinfo
If strerror <> "" then
Response. Write obj. errorinfo
End if
OBJ. Free
Set OBJ = nothing
%>

Ii. Add a text watermark

<%
Set OBJ = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepic server. mappath ("25.jpg") '''
OBJ. Quality = 75
OBJ. txtmarkfont = "文" ''' sets the watermark text font.
OBJ. txtmarkbond = false ''' set the watermark text width.
OBJ. markrotate = 0 ''' watermark text Rotation Angle
OBJ. txtmarkheight = 25 ''' height of the watermark text
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

<%
Set OBJ = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepic server. mappath ("25.jpg") '''
OBJ. loadimgmarkpic server. mappath ("blend.bmp") ''' load the 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
%>

In fact, adding a watermark to an image is that simple. Then I will explain the other two main usage of the wsimage. dll component, including:
Crop an image to generate a thumbnail.
I still get used to it and add comments with the code to describe:
Crop images:

<%
Set OBJ = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepic server. mappath ("25.jpg ")
OBJ. Quality = 75
OBJ. cropimage server. mappath ("25_crop.jpg"), 200,200, ''' defines the cut size and 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.

Generate image thumbnails:

<%
Set OBJ = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepic server. mappath ("25.jpg") ''' load the image
OBJ. Quality = 75
OBJ. outputspic server. mappath ("25_s.jpg"), 0.5, 0.5, 3 ''' defines the size of the thumbnail.
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"), 200,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.

Related Article

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.