Components - AspJPEG
| Overview | ||||||||||||||||||||||||||||||||||||||||||||||||
|
AspJpeg is an active server component that creates resized versions of images. AspJpeg enables your ASP application to dynamically create high-quality thumbnails of images in just a few lines of code. An original image may be in any of the following formats: JPEG, GIF, BMP, or PNG.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| AspJpeg Methods/Properties | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Binary Canvas Expired Height Interpolation OriginalHeight OriginalWidth Quality RegKey Version Width |
||||||||||||||||||||||||||||||||||||||||||||||||
| Binary As Variant (read-only) New in AspJpeg 1.3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Returns a binary array of bytes representing a thumbnail.
This property is useful
for saving thumbnails in the database as BLOBs.
Can be used instead of Save/SendBinary if the ultimate
destination of the thumbnail is a database table.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Canvas As Object (read-only) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Returns the Canvas object which, along with its sub-objects Canvas.Font,
Canvas.Pen and Canvas.Brush, enables writing and drawing over an image.
The full description of the Canvas object can be found in the end of this section.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Expires As Date (read-only) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Returns the component's expiration date. If a valid registration
key is installed, returns 9/9/9999.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Height As Long (read/write) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Specifies a new image height (in pixels). Must be called after an image
is opened via the Open method.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolation As Long (read/write) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Specifies an image resizing algorithm. The following values are currently
supported: 0 (Nearest-Neighbor), 1 (Bilinear, default) and 2 (Bicubic).
The Nearest-Neighbor (NN) is the fastest but provides low-quality thumbnails. The Bilinear method offers much better thumbnail quality but is approximately 2 times as slow as NN. The Bicubic method is approximately twice as slow as Bilinear and 4 times as slow as NN, but supposedly offers the highest quality. In many cases, however, it provides little, if any, noticeable improvement over the Bilinear method.
Default: 1 (Bilinear).
|
||||||||||||||||||||||||||||||||||||||||||||||||
| OriginalHeight As Long (read-only) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Returns the original image height (in pixels). Can only be called after an image
is opened via the Open method. Use this property to preserve
the original aspect ratio of an image.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| OriginalWidth As Long (read-only) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Returns the original image width (in pixels).Can only be called after an image
is opened via the Open method. Use this property to preserve
the original aspect ratio of an image.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Quality As Long (read/write) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Specifies the degree of compression loss. Affects the resultant
image quality and file size.
Accepts an integer value in the range 0 to 100, 0 being the lowest quality, highest loss and smallest file size. The higher the value the higher the image quality, and the larger the file size.
The property Quality is set to 80 by default which offers a close-to-optimal
combination of image quality and file size.
Changing this property is generally not recommended.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| RegKey As String (write-only) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Specifies the registration key. If this property is not set, AspJpeg
looks for a registration key in the system registry.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Version As String (read-only) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Returns the current version of the component in the format "1.2.0.0". |
||||||||||||||||||||||||||||||||||||||||||||||||
| Width As Long (read/write) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Specifies a new image width (in pixels). Must be called after an image
is opened via the Open method.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| AspJpeg Methods | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Close Crop DrawImage FlipH FlipV Open OpenBinary Save SendBinary Sharpen RotateL RotateR |
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub Close() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Closes a file opened via the Open method. This method is called
automatically upon the destruction of the AspJpeg object, so you do not have
to call it explicitly, unless there is an immediate need to
free the file handle (such as, if you need to delete the file).
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub Crop(x0 As Long, y0 As Long, x1 As Long, y1 As Long) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Cuts edges off of a thumbnail. For this method to take effect,
you must call it before calling .Save or .SendBinary.
The arguments (x0, y0) and (x1, y1) are the coordinates of the upper-left and lower-right corners of the desired cropped image within the thumbnail. For example, if the original large image is 300 pixels wide and 200 pixels high, the following sequence will produce a cropped thumbnail which is 60 pixels wide and 40 pixels high:
Jpeg.Width = 120 |
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub DrawImage(X As Long, Y As Long, Picture As Object, Optional Opacity = 1, Optional TranspColor, Optional TranspDeviation = 0) New in AspJpeg 1.3 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Draws an image on top of the current image. X and Y
are coordinates (in pixels) of the upper-left corner
of Picture within the current image.
Picture is an instance of the AspJpeg object.
Opacity is a number between 0 and 1 which specifies the degree of opacity when Picture is blended onto the current image. Default value: 1 (opaque). TranspColor specifies the color of pixels within Picture to be made transparent when blending the picture onto the current image. This must be an HTML-style hexadecimal number, e.g. &HFF0000 (red). By default, no pixels will be made transparent.
TranspDeviation is a number between 0 and 255 which specifies
an allowable deviation of the RGB color values from TranspColor.
Default value: 0. If TranspColor is not specified, this argument is
ignored.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub FlipH() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Flips the resultant thumbnail horizontally. For this method to take effect,
you must call it before calling .Save or .SendBinary.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub FlipV() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Flips the resultant thumbnail vertically. For this method to take effect,
you must call it before calling .Save or .SendBinary.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub Open(Path As String) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Opens a JPEG image for resizing. Path must be a physical path
to the image.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub OpenBinary(ImageBlob As Variant) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Same as Open, but the image is opened from a binary memory source
(such as an ADO recordset) rather than a file. Use this function to resize images
residing in a database as blobs, e.g.
Set rs = Server.CreateObject("adodb.recordset")
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Open image directly from recordset
...
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub Save(Path As String) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Resizes the currently opened image using parameters
specified by various properties.
Save the resultant image thumbnail to a file specified by Path.
If a file with this name already exists it will be overwritten.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub SendBinary(Optional ContentDisposition) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Resizes the currently opened image using parameters
specified by various properties. Sends the resultant image
directly to the client browser by internally calling
Response.BinaryWrite. Automatically sets the Content-Type
header to "image/jpeg".
If ContentDisposition is set, also sets the "Content-Disposition" header to a value specified by this argument. A typical value for this argument is "filename=image_name.jpg" or "filename=attachment;image_name.jpg"
You can only use this method in an ASP/IIS environment.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub Sharpen(Radius As Double, Amount As Double) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Sharpens an image. Radius
specifies the radius of scanning (in pixels) around each pixel.
This argument should normally be set to 1 or 2.
Amount specifies the degree of sharpness (in %). This argument
must be greater than 100. For this method to take effect, you must call it before calling .Save or .SendBinary.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub RotateL | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Rotates the image 90 degrees counter-clockwise. This method also causes the
properties Width and Height to switch values.
For this method to take effect, you must call it before calling .Save or .SendBinary.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sub RotateR | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Rotates the image 90 degrees clockwise. This method also causes the
properties Width and Height to switch values.
For this method to take effect, you must call it before calling .Save or .SendBinary.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Jpeg.Canvas Object Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Example | ||||||||||||||||||||||||||||||||||||||||||||||||
' Create instance of AspJpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Compute path to source image
Path = Server.MapPath("images") & "\clock.jpg"
' Open source image
Jpeg.Open Path
' Decrease image size by 50%
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
' Apply sharpening if necessary
' Jpeg.Sharpen 1, 130
' create thumbnail and save it to disk
Jpeg.Save Server.MapPath("images") & "\clock_small.jpg"
|
