AspJpeg of ASP Watermark Component code example _ application technique

Source: Internet
Author: User
Tags microsoft iis
1, what is AspJpeg?
AspJpeg is a powerful image processing component based on the Microsoft IIS environment, and there are not many Chinese articles on the network for detailed and in-depth introduction, even if there is a general only involves picture thumbnails and image watermark, which is closely related to the English version.
AspJpeg can use very little code in your asp/asp. NET applications to create high-quality thumbnail images, supported image formats are: JPEG, GIF, BMP, TIFF, PNG

AspJpeg can mainly do:

Generate thumbnail pictures
To generate a watermark picture
Picture Merge
Picture Cutting
Database support
Security Code Technology

2, AspJpeg function Summary
Supports JPEG, GIF, BMP, TIFF, and PNG format pictures. The output format is always JPEG
Source pictures can originate from disk, memory, or recordset (database)
Thumbnail images can be saved to disk, memory, or HTTP stream
Supports three ways to change size: Nearest-neighbor, bilinear, and Bicubic.
You can add pictures or text on top of a picture.
Support picture in painting
Supports replication, inversion, rotation, sharpening, and grayscale adjustment.
You can adjust the compression ratio to get the best output effect and size.
Extract EXIF and IPTC data from JPEG images.
Cmyk-rgb Conversion
Read/write access to individual pixels of the an image. (Read/write access from the image to the image element.) )

3, AspJpeg system requirements
Windows 95/98/nt/2000/xp/2003, and
IIS 4.0+ and Asp/asp.net, or
Visual Basic 5.0+, or
Visual C + + 5.0+, or
Any development environment supporting COM.

4, AspJpeg installation
New Installation:
When you enter a serial number during aspjpeg installation, if the installation location disk is formatted as NTFS, there may be a problem with access rights, and you need to manually set up the installation directory to have access to everyone.

Update Installation:
If you have previously installed a different version of the AspJpeg component, you will need to uninstall the original component before you install the new version.
Stop IIS First
Net Stop iisadmin/y
Uninstall Legacy Components
regsvr32/u path/aspjpeg.dl (path for installation)
Restart IIS
Net Start W3SVC

Then perform a new installation or copy the AspJpeg.dll file to the installation directory for manual installation:
regsvr32 path/aspjpeg.dll (path for installation)

If you do not enter a serial number or manual installation during normal Setup, you must include the following in the registry, for convenience you can save the following code directly as a. reg document and import the registry:
Windows Registry Editor Version 5.00

[Hkey_local_machine\software\persits Software\aspupload3\regkey]
@= "21764-40765-60456"


5. How do I create a aspjpeg instance?
Set Jpeg = Server.CreateObject ("Persits.jpeg")



6, how to view the expiration time (whether registration success)?
Set Jpeg = Server.CreateObject ("Persits.jpeg")
Response.Write Jpeg.expires


Registration success expires When: 9999-9-9
Otherwise: installation date plus 1-month period

7, how to use the AspJpeg component to generate thumbnail images?
<%
Set Jpeg = Server.CreateObject ("persits.jpeg") ' Create instance
Path = Server.MapPath (".. /images/apple.jpg ")" Process picture path
Jpeg.open Path ' Open picture
' Adjust width and height to original 50%
Jpeg.width = JPEG.ORIGINALWIDTH/2
Jpeg.height = JPEG.ORIGINALHEIGHT/2
Jpeg.save Server.MapPath ("apple_small.jpg") ' Save pictures to disk
Jpeg.Close:Set Jpeg = Nothing
%>


8, how to use the AspJpeg component to generate image 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 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
%>


9, how to use aspjpeg components for picture merging?
AspJpeg 1.3+ enables you to place images on top of all other via the method DrawImage. To must create two instances of the AspJpeg objects and populate both of them with images via calls T o Open (or openbinary).  When calling Canvas.drawimage, the 2nd instance of AspJpeg is passed as a argument to-I, along with the X and Y Offsets (in pixels):
With this method, you must create two AspJpeg instance objects
<%
Set JPEG1 = Server.CreateObject ("Persits.jpeg")
Set JPEG2 = Server.CreateObject ("Persits.jpeg")
Jpeg1.open Server.MapPath ("T.jpg")
Jpeg2.open Server.MapPath ("T1.jpg")
Jpeg1.Canvas.DrawImage, Jpeg2 ' optional arguments omitted
Jpeg1.save Server.MapPath ("Tt.jpg")
%>


10, how to use aspjpeg components for picture cutting?
AspJpeg 1.1+ is also capable of cutting out edges from, or cropping, the resultant thumbnails via the method crop (x0, y0, x1, y1). The size of the cropped image is specified by the coordinates of Upper-left and lower-right corners within the Resulta NT thumbnail, not the original large image.
<%
Set Jpeg = Server.CreateObject ("Persits.jpeg")
Jpeg.open Server.MapPath ("T.jpg")
Jpeg. Crop, JPEG. WIDTH-20, JPEG. Height-10
Jpeg.save Server.MapPath ("Tt.jpg")
Response.Write ("%>


11, how to use the AspJpeg component to create security code?
The principle of creating a security code is similar to creating a watermark.
<%
function make_randomize (max_len,w_n) ' max_len generation 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

' Create a picture of the security code.
Random_num=make_randomize (4,1) ' generates a 4-digit security Code
Session ("Random_num") =random_num ' to call session, no session of the security code is completely meaningless. Oh.

Set Jpeg = Server.CreateObject ("persits.jpeg") ' Invoke component
Jpeg.open Server.MapPath ("t.jpg") ' Open the prepared picture
Jpeg.Canvas.Font.Color = &hffffff
Jpeg.Canvas.Font.Family = "Arial Black"
Jpeg.Canvas.Font.Bold = False
Jpeg.Canvas.PrintText 0,-2, Random_num
Jpeg.save Server.MapPath ("tt.jpg") ' Save
%>



12, how to let the AspJpeg component support database?
The picture is stored in the database can only be stored in binary data, here is the AspJpeg binary method, the following two AspJpeg user manual for example, please refer to the AspJpeg user manual:
Opening Images from Memory
<% ' Using ADO, open database with an image blob
strconnect = "Driver={microsoft Access DRIVER (*.mdb)};D bq=" & Server.MapPath (".. /db/aspjpeg.mdb ")
Set rs = Server.CreateObject ("Adodb.recordset")
SQL = "Select Image_blob from images2 where id =" & Request ("id")
Rs. Open SQL, StrConnect, 1, 3
Set Jpeg = Server.CreateObject ("Persits.jpeg")
' Open image directly from recordset
Jpeg.openbinary rs ("Image_blob"). Value
' Resize
Jpeg. width = Request ("width")
' Set new height, preserve original aspect ratio
Jpeg. Height = jpeg. OriginalHeight * jpeg. Width/jpeg. OriginalWidth
Jpeg.sendbinary
Rs. Close
%>


Output to Memory
<%
...
Set rs = Server.CreateObject ("Adodb.recordset")
Rs. Open "Images", StrConnect, 1, 3
Rs. AddNew
RS ("Image_blob"). Value = Jpeg.binary
Rs. Update
...
%>
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.