ASP watermark component-combined aspjpeg code example

Source: Internet
Author: User
Tags microsoft iis

1. What is aspjpeg?
Aspjpeg is a powerful image processing component based on Microsoft IIS environment. It provides detailed and in-depth introduction to Chinese on the network. Article There are not many, even if there are generally only image thumbnails and image watermarks, which are closely related to the English version.
Aspjpeg can be used with very few Code In your asp/ASP. NET application Program Allows you to dynamically create high-quality thumbnail images. Supported image formats include JPEG, GIF, BMP, Tiff, and PNG.

The main functions of aspjpeg are as follows:

Generating thumbnail slices
Generate watermark image
Image Merging
Image Cutting
Database Support
Security code technology

2. asp JPEG feature Summary
Supports JPEG, GIF, BMP, Tiff, and PNG images. The output format is always JPEG.
Source images can be from disks, memory, or record sets (databases)
Thumbnails can be saved to disks, memory, or HTTP streams.
The following three methods are supported: nearest-neighbor, bilinear, and bicubic.
You can add images or text to images.
Supports in-picture
Supports replication, reversal, 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 an image. (read/write access to any pixel from the image .)

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. Install aspjpeg
New installation:
Enter the serial number during the aspjpeg installation process. If the disk format of the installation location is NTFS, access permission may occur. You need to manually set the installation directory to have access to everyone.

Update and install:
If you have installed another version of the aspjpeg component, You Need To uninstall the original component before installing the new version.
Stop IIS first
Net stop IISADMIN/y
Uninstall old components
Regsvr32/u path/aspjpeg. DL (path is the installation path)
Restart IIS
Net start w3svc

Then perform a fresh installation or copy the aspjpeg. dll file to the installation directory for manual installation:
Regsvr32 path/aspjpeg. dll (path is the installation path)

If no serial number is entered during normal installation or manual installation, you must add the following items to the Registry. For convenience, you can directly Save the following code as the. Reg document and import it to the registry:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE \ SOFTWARE \ persits SOFTWARE \ aspupload3 \ regkey]
@ = "21764-40765-60456"

5. How to create an aspjpeg instance?
Set JPEG = server. Createobject ("persits. jpeg ")

6. How can I check the expiration time (whether the registration is successful )?
Set JPEG = server. Createobject ("persits. jpeg ")
Response. Write jpeg. Expires

The expiration time for successful registration is 9999-9-9
Otherwise: the installation date plus the one-month period

7. How to Use the aspjpeg component to generate image thumbnails?
<%
set JPEG = server. createobject ("persits. JPEG ") 'create an instance
Path = server. mappath (".. /images/apple.jpg ") 'process image path
JPEG. open Path 'open image
'adjust the width and height to the original 50%
JPEG. width = JPEG. originalwidth/2
JPEG. height = JPEG. originalheight/2
JPEG. save server. mappath ("apple_small.jpg") 'saves the image to the disk
JPEG. close: Set JPEG = nothing
%>

8. How to Use the aspjpeg component to generate an 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 bold
JPEG. canvas. print 10, 10, "Copyright (c) XYZ, Inc. "
Print coordinates x print the characters that y needs to print
The following is a frame processing for the image
JPEG. canvas. pen. color = & h000000' 'black color
JPEG. canvas. pen. width = 2 paint width
JPEG. canvas. brush. whether or not solid = false is 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
%>

9. How to Use the aspjpeg component to merge images?
aspjpeg 1.3 + enables you to place images on top of each other via the method drawimage. to use this method, you must create two instances of the aspjpeg objects and populate both of them with images via callto open (or openbinary ). when calling canvas. drawimage, the 2nd instance of aspjpeg is passed as an argument to this method, along with the X and Y offsets (in pixels):
use this method, you must create two aspjpeg instance objects
<%
set to 1 = server. createobject ("persits. JPEG ")
SET protocol 2 = server. createobject ("persits. JPEG ")
protocol 1.open server. mappath ("t.jpg")
jpeg2.open server. mappath ("t1.jpg")
container 1.canvas. drawimage 10, 10, interval 2 'optional arguments omitted
using 1.save server. mappath ("tt.jpg")
%>

10. How to Use the aspjpeg component to cut images?
aspjpeg 1.1 + is also capable of cutting off 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 the upper-left and lower-right corners within the resultant thumbnail, not the original large image.
<%
set JPEG = server. createobject ("persits. JPEG ")
JPEG. open Server. mappath ("t.jpg")
JPEG. crop 20, 30, JPEG. width-20, JPEG. height-10
JPEG. save server. mappath ("tt.jpg")
response. write ("")
%>

11. How can I use the aspjpeg component to create a 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, and 1 may only contain 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

'The image that generates the security code.
Random_num = make_randomize () ''generates a four-digit security code.
Session ("random_num") = random_num 'indicates that the session is called. The security code without the session is meaningless. Haha.

Set JPEG = server. Createobject ("persits. jpeg") 'Call the component
JPEG. Open Server. mappath ("t.jpg") 'Open the prepared Image
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 can I enable the aspjpeg component to support databases?
images can only be saved as binary data in the database. The binary method of aspjpeg is used here. The following uses the code in two aspjpeg user manuals as an example. For details, see the aspjpeg User Manual:
opening images from memory
<% 'using ado, open database with an image blob
strconnect = "driver = {Microsoft Access Driver (*. MDB)}; DBQ = "& 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.