Watermark images with ASPCodeAnd method (reprinted http://hi.baidu.com/ibanaz/blog/item/ec5b642731b28103918f9dcf.html)
How can I use ASP to watermark image codes and methods?
I hope to write out specific code and methods.
----------------------------------------------------------------------------
Adding watermarks to Images Using ASP requires components... common applications include aspjpeg software and wsimage software developed by the Chinese people. You can search and download the two software online. We recommend that you use the wsimage developed by the Chinese people. After all, it is a Chinese version and easy to operate.
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)
<
Setobj = server. Createobject ("wsimage. Resize") ''call the component
OBJ. loadsoucepicserver. mappath ("25.jpg" )''open the image. The image name is 25.jpg.
OBJ. getsourceinfoiwidth, iheight
Response. Write "Image Width:" & iwidth & "<br" ''To get the Image Width
Response. Write "Image Height:" & iheight & "<br" ''To get the Image Height
Strerror = obj. errorinfo
Ifstrerror <"" then
Response. writeobj. errorinfo
Endif
OBJ. Free
Setobj = nothing
''' ------------------------------------------------------------------ ''
2: Add a text watermark
setobj = server. createobject ("wsimage. resize ")
obj. loadsoucepicserver. mappath ("25.jpg")'' loads images
obj. quality = 75
obj. txtmarkfont = "文" ''sets the watermark text font
obj. txtmarkbond = false'': Specifies the width of the watermark text.
obj. markrotate = 0'' watermark text Rotation Angle
obj. txtmarkheight = 25'' watermark text height
obj. addtxtmarkserver. mappath ("txtmark.jpg"), "Take you away", & h00ff00 &, 10, 70
strerror = obj. errorinfo '': The image name is generated. The text color is the position of the watermark in the image.
ifstrerror <" then
response. writeobj. errorinfo
endif
obj. free
setobj = nothing
''----------------------------------------------------------------''
3. Add an image watermark
<
Setobj = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepicserver. mappath ("25.jpg")''
OBJ. loadimgmarkpicserver. mappath ("blend.bmp ")''
OBJ. Quality = 75
OBJ. addimgmarkserver. mappath ("imgmark.jpg"), 315,220, & hffffff, 70
Strerror = obj. errorinfo '': generate the image name. The text color is the position of the watermark in the image.
Ifstrerror <"" then
Response. writeobj. errorinfo
Endif
OBJ. Free
Setobj = 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:
<
Setobj = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepicserver. mappath ("25.jpg ")
OBJ. Quality = 75
OBJ. cropimageserver. mappath ("25_crop.jpg"), 200,200, 10, ''defines the cut size and the name of the generated image.
Strerror = obj. errorinfo
Ifstrerror <"" then
Response. writeobj. errorinfo
Endif
OBJ. Free
Setobj = 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:
<
Setobj = server. Createobject ("wsimage. Resize ")
OBJ. loadsoucepicserver. mappath ("25.jpg")'' load the image
OBJ. Quality = 75
OBJ. outputspicserver. mappath ("25_s.jpg"), 0.5, 0.5, 3 ''defines the name of the thumbnail, that is, the size.
Strerror = obj. errorinfo
Ifstrerror <"" then
Response. writeobj. errorinfo
Endif
OBJ. Free
Setobj = nothing
Detailed description:
There are four ways to export a thumbnail:
(1) obj. outputspicserver. 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. outputspicserver. mappath ("25_s.jpg"), 200,0, 1
The output width is 200, and the output height scales with the ratio column.
(3) obj. outputspicserver. mappath ("25_s.jpg"), 0,200, 2
The output height is 200, and the output width scales with the ratio column.
(4) obj. outputspicserver. 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.
Hope this is technicalArticleIt helps you.
Bytes ----------------------------------------------------------------------------------------------------------
Because I am busy recently, I found a smallProgramYou can add stamps to your images in batches through the Web.
At present, this program has not been tested, the status is unknown, there is time to study again, forgive me ....
: Http://www.mbsky.com/SoftView/SoftView_38956.html