aspjpeg is a very powerful image processing component, pure English version. However, there are already free versions and cracked versions, but there are not many articles that introduce them in detail and in-depth. Even if there are, they only involve image thumbnails and image watermarks. Maybe it's because it's in pure English.
Here I will talk about the advanced usage of aspjpeg based on these issues. The technologies here mainly include:
Image thumbnails, image watermarks, security code technology, image cutting, image merging, database support, introduction of more uncommon methods and some related practical technologies
The only shortcoming of aspjpeg is that the output method is relatively simple. Here, we mainly talk about this output method that saves the image processing and then calls it. In addition, I am lazy, so some codes are still quoted from the original documents, and I will occasionally explain what I don’t understand!
Comrades who have studied VB or .net will definitely understand it at a glance. The brush is coming. hehe.
1. Picture thumbnail
<%
Set Jpeg = Server.CreateObject("Persits.Jpeg") calls the component
Path = Server.MapPath("images") & "clock.jpg" The path of the image to be processed
Jpeg.Open Path opens the image to 1/2 the height and width of the original image.
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
save image
Jpeg.Save Server.MapPath("images") & "clock_small.jpg"
%>
<IMG SRC="images/clock_small.jpg"> View processed images
2. Picture watermark
<%
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open Server.MapPath("images/dodge_viper.jpg")
Start writing text
Jpeg.Canvas.Font.Color = &000000' red color
Jpeg.Canvas.Font.Family = "Courier New" Font
Jpeg.Canvas.Font.Bold = True whether to bold
Jpeg.Canvas.Print 10, 10, "Copyright (c) XYZ, Inc."
Print coordinate x Print coordinate y Characters to be printed The following is the border processing of the picture
Jpeg.Canvas.Pen.Color = &H000000' black color
Jpeg.Canvas.Pen.Width = 2 brush width
Jpeg.Canvas.Brush.Solid = False whether to bold
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 code is similar to adding watermark. Many friends ask me for specific coding technology. I will write it down and share it with you here. Most people will not tell them. hehe.
<%
Function to generate security code www.downcodes.com
function make_randomize(max_len,w_n) max_len generates 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(4,1) to generate a 4-digit security code
session("random_num")=random_num Why call session? It is completely meaningless without the session security code. Haha
Set Jpeg = Server.CreateObject("Persits.Jpeg") calls the 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
%> <img src="infos/random_pic/random_index.bmp" border="0" align="absmiddle">
Do it yourself. hehe.
4. Picture cutting.
For a long time, people who don't know about aspjpeg thought that they couldn't use it to cut.
In fact, there is such a method
crop x1,y1,x2,y2
Cut the x coordinate of the upper left corner of the rectangle, and the y coordinate of the lower right corner of the rectangle. I will give a demonstration below.
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 Starting to cut is actually to remove the lower part that exceeds 52 pixels.
jpeg.save server.MapPath("/temp_pic/small_1.gif") How about saving? It's very simple.
5. Image merging
Here we are going to add the logo image to the dodge_viper.jpg image. In fact, the image merging method can also be used to dynamically add watermarks.
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 also save the changed dodge_viper.jpg first and then enter it. I personally don't like to use the sendBinary method because it is prone to errors when the network speed is slow. Not much in terms of speed either. hehe.
6. Database support
I won’t go into details here. In fact, it is the Binary method. As we all know, images can only be stored as binary files when stored in the database. So the code was written lazily.
7. More methods to introduce
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 the code introduced on it
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
Author of this article: Yulang This article is reprinted, and the copyright belongs to the original author.