Home Download and Buy What's New Live Demos Contact Us
 
1.ASPJpeg
5.Gif
8.Pen

Search this site
 

 

Object Reference
ASPJpeg Object

ASPJpeg is the main object which encapsulates most of the component's functionality. This object is creatable as follows:

VB Script:
Set Jpeg = Server.CreateObject("Persits.Jpeg")

VB:
Dim Jpeg As New ASPJPEGLib.ASPJpeg

C#:
ASPJPEGLib.IASPJpeg objJpeg = new ASPJPEGLib.ASPJpeg();

Properties Methods
AlphaExists
AlphaPixels
Binary
Canvas
Expires
Gif
Height
Interpolation
OriginalComponents
OriginalFormat
OriginalHeight
OriginalResolutionX
OriginalResolutionY
OriginalWidth
Pixels
PNGOutput
PreserveAspectRatio
PreserveICCProfile
PreserveMetadata
Progressive
Quality
RegKey
ResolutionX
ResolutionY
TiffIndex
TransparencyColor
TransparencyColorExists
Version
Width
WindowsDirectory
AddMetadataItem
Adjust
AlphaToImage
ApplyFilter
Close
Crop
DrawImage
FlattenAlpha
FlipH
FlipV
Grayscale
LogonUser
New
Open
OpenBinary
OpenInfo
OpenInfoBinary
RemoveAlpha
ReplaceColor
Rotate
RotateL
RotateR
Save
SaveUnique
SendBinary
Sepia
SetAlpha
Sharpen
ToGrayscale
ToRGB

ASPJpeg Properties

AlphaExists As Boolean (read-only)
Returns True if the current image has an alpha channel associated with it (e.g. if a PNG file with an alpha channel was opened.) The alpha channel, if present, only has effect when the image is saved in PNG format (the PNGOutput property is set to True.)

This property was introduced in Version 2.1.

See also: Chapter 10 - PNG Output.

AlphaPixels (X As Long, Y As Long) As Integer (read/write)
Sets or retrieves the alpha value of a pixel specified via 0-based (X, Y) coordinates. This property can only be used if the current image has an alpha channel associated with it, which can be determined using the AlphaExists property. This property returns, or is assigned, an integer value in the range 0 to 255. The X and Y coordinates must be in the range (0, Width - 1) and (0, Height - 1), respectively.

This property was introduced in Version 2.1.

See also: Section 10.3 - Alpha Channel Management.

Binary As Variant (read-only)
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.

See also: Section 2.4 - Output to Memory.

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.

See also: Chapter 5 - Drawing & Typing.

Expires As Date (read-only)
Returns the component's expiration date. If a valid registration key is installed, returns 9/9/9999.

See also: Section 1.5 - Expiration Mechanism.

Gif As Object (read-only)
Returns the Gif object which manages GIF output. This property was introduced by version 2.0.

See also: Chapter 9 - GIF Output.

Height As Long (read/write)
Specifies a new image height (in pixels). Must be called after an image is opened via the Open or OpenBinary methods.

Side effect: if PreserveAspectRatio is set to True, changing this property automatically changes Width to preserve the original aspect ratio of the image.

See also: Section 2.1 - Thumbnail-Creating Steps.

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).

See also: Section 4.1 - Resizing Algorithms.

OriginalComponents As Long (read-only)
Returns the number of original color components for the image: 3 for RGB, 4 for CMYK and 1 for grayscale images. This property is not affected by a successful call to ToRGB.
OriginalFormat As String (read-only)
Returns the format of the currently opened image. Possible values are "JPG", "GIF", "PNG", "BMP" and "TIF" for JPEG, GIF, PNG, BMP and TIFF formats, respectively.
OriginalHeight As Long (read-only)
Returns the original image height (in pixels). Can only be called after an image is opened via the Open or OpenBinary methods. Use this property to preserve the original aspect ratio of an image.

See also: Section 2.1 - Thumbnail-Creating Steps.

OriginalResolutionX As Single (read-only)
Returns the original image resolution along the X-axis (in DPI). If this property returns 1, the resolution may be available via an EXIF tag, or not available at all (in the latter case it should be assumed to be 72 DPI).

See also: Section 8.2 - Image Resolution.

OriginalResolutionY As Single (read-only)
Returns the original image resolution along the Y-axis (in DPI). If this property returns 1, the resolution may be available via an EXIF tag, or not available at all (in the latter case it should be assumed to be 72 DPI).

See also: Section 8.2 - Image Resolution.

OriginalWidth As Long (read-only)
Returns the original image width (in pixels).Can only be called after an image is opened via the Open or OpenBinary methods. Use this property to preserve the original aspect ratio of an image.

See also: Section 2.1 - Thumbnail-Creating Steps.

Pixels (X As Long, Y As Long) As Variant (read/write)
Sets or retrieves the color components of an individual pixel specified via 0-based (X, Y) coordinates. This property returns, or is assigned, a Variant array of color components. The size of the array must match this image's color space (3 items for RGB, 4 for CMYK, 1 for grayscale). The X and Y coordinates must be in the range (0, Width - 1) and (0, Height - 1), respectively. This is the default property of the ASPJpeg object.

See also: Section 8.3 - Access to Individual Pixels.

PNGOutput As Boolean (read/write)
If set to True, the image is saved in the PNG format instead of JPEG. The alpha channel, if any, is preserved. False by default.

This property was introduced in Version 2.1.

See also: Chapter 10 - PNG Output.

PreserveAspectRatio As Boolean (read/write)
False by default. If set to True, creates a link between the Width and Height properties so that changing one dimension will automatically change the other to preserve the original aspect ratio of the image.

See also: Section 2.1 - Thumbnail-Creating Steps.

PreserveICCProfile As Boolean (read/write)
False by default. If set to True, preserves the ICC profile of the original image in a thumbnail. Must be set before calling Open or OpenBinary. This property was introduced by version 2.4.

See also: Section 7.5 - Metadata Preservation.

PreserveMetadata As Boolean (read/write)
False by default. If set to True, preserves the Exif and IPTC metadata of the original image in a thumbnail. Must be set before calling Open or OpenBinary. This property was introduced by version 1.9.

See also: Section 7.5 - Metadata Preservation.

Progressive As Boolean (read/write)
False by default. If set to True, generates a progressive JPEG image, i.e. an image that progressively gets sharper on the web page as it is being downloaded. Currently, Netscape is the only major browser supporting gradual rendering of progressive JPEGs, other browsers just display the entire image at once after it has been fully downloaded.

See also: Section 8.4 - Progressive JPEGs.

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.

This property is set to 80 by default which offers a close-to-optimal combination of image quality and file size.

See also: Section 4.5 - Adjusting Image Compression.

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.

See also: Section 1.5 - Expiration Mechanism.

ResolutionX As Single (read/write)
Specifies a new image resolution along the X-axis in DPI.

See also: Section 8.2 - Image Resolution.

ResolutionY As Single (read/write)
Specifies a new image resolution along the Y-axis in DPI.

See also: Section 8.2 - Image Resolution.

TiffIndex As Long (write-only)
Specifies the 1-based index of an image to be opened from a multi-page TIFF file. For this property to take effect, it must be set before calling Open or OpenBinary. 1 by default. Used only when the image being opened is in TIFF format, ignored for all other image formats. You can find out the number of pages in a TIFF image via the Info collection.

See also: Section 7.4 - TIFF Support.

TransparencyColor As Long (read-only)
If the currently opened image is a GIF which has a transparency color, this property returns this color as a long integer in the format &H00rrggbb. If the image does not have a transparency color, this property will throw an error. Always check the property TrasparencyColorExists before retrieving the transparency color of the image. This property was introduced by version 1.6.

See also: Section 6.2 - GIF Transparency.

TransparencyColorExists As Boolean (read-only)
Returns True if the currently opened image is a GIF with a transparency color. Returns False otherwise. Check this property before attempting to access TransparencyColor. This property was introduced by version 1.6.

See also: Section 6.2 - GIF Transparency.

Version As String (read-only)
Returns the current version of the component in the format "1.6.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 or OpenBinary methods.

Side effect: if PreserveAspectRatio is set to True, changing this property automatically changes Height to preserve the original aspect ratio of the image.

See also: Section 2.1 - Thumbnail-Creating Steps.

WindowsDirectory As String (read-only)
Returns the Windows directory on the current machine, such as "c:\Windows". This property is useful to compute the path to a font file required by the PrintTextEx method.

This property was introduced in Version 1.8.

See also: Section 5.3 - Advanced Text Drawing with PrintTextEx.

ASPJpeg Methods

Sub AddMetadataItem(ID As String, Value As String)
Adds or replaces an IPTC item in the current image. ID must be an IPTC field name from the table shown in Section 7.3 - IPTC Item List. Value is a string to be inserted into this field. Value cannot be longer than 1000 characters.

To use this method, the property PreserveMetadata must be set to True before the image is opened.

When ID is set to "IptcCopyrighted", Value must be set to either "True" or "False".

As of Version 2.0.0.1, ID can also be set to "IptcKeywordsAdd" which adds a new "IptcKeywords" entry instead of replacing an existing one. As of Version 2.1, ID can also be set to "IptcKeywordsRemove" which removes all existing keywords so that a whole new set of keywords can be specified.

This method was introduced in Version 2.0.

See also: Section 7.6 - Metadata Editing.

Sub Adjust(Function As Long, Value As Double)
A multi-purpose method which adjusts brightness, contrast and saturation of an RGB image.

Function specifies the operation code: 1 for brightness, 2 for contrast and 3 for saturation. Value specifies the operation-specific value: a number in the range [-1, 1] for brightness and saturation, and in the range [0.001, 5] for contrast.

This method was introduced in version 1.7. As of Version 2.6, this method is obsolete, use the method ApplyFilter instead.

See also: Section 8.5 - Brightness, Contrast and Saturation.

Sub AlphaToImage()
Replaces the color values of each pixel of the current image with the respective values of its alpha channel. Thus the alpha channel becomes an image in its own right (in grayscale color space.) This method is useful if the alpha channel of an image needs to be drawn on. If the image has no alpha channel, this method throws an exception.

This method was introduced in Version 2.1.

See also: Section 10.3 - Alpha Channel Management.

Sub ApplyFilter(FilterID As Long, Param1 As Double, Optional Param2)
Implements several common image filters, such as brightness, contrast, blur, etc. FilterID specifies which filter to use. Param1 and Param2 are filter-specific parameter values. All currently implemented filters, their parameters and sample output are described here.

This method was introduced in Version 2.6.

See also: Section 8.6 - Filters.

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 off edges from thumbnail. For this method to take effect, you must call it before calling .Save, .SendBinary or .Binary.

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.

See also: Section 4.3 - Image Cropping.

Sub DrawImage(X As Long, Y As Long, Picture As ASPJpeg, Optional Opacity = 1, Optional TranspColor, Optional TranspDeviation = 0)
Obsolete. Same as Canvas.DrawImage. Supported for backwards compatibility only.
Sub FlattenAlpha(Color As Long)
Combines the pixels of the current image with the specified background Color in accordance with the current alpha channel, and then removes the alpha channel. Has no effect if the image has no alpha channel. This method is useful for converting PNG images to JPEG format.

This method was introduced in Version 2.7.

See also: Section 10.3 - Alpha Channel Management.

Sub FlipH()
Flips the resultant thumbnail horizontally. For this method to take effect, you must call it before calling .Save, .SendBinary or .Binary.

See also: Section 4.4 - Image Flipping and Rotation.

Sub FlipV()
Flips the resultant thumbnail vertically. For this method to take effect, you must call it before calling .Save, .SendBinary or .Binary.

See also: Section 4.4 - Image Flipping and Rotation.

Sub Grayscale(Method As Long)
Turns a color image into grayscale. Method specifies the conversion algorithm. Valid values: 0 (desaturation), 1 (recommended algorithm) and 2 (a slight variation of Method 1).

See also: Section 4.6 Grayscale Conversion.

Sub LogonUser(Domain As String, Username As String, Password As String, Optional Flag )
Impersonates an arbitrary user account. Use this method to avoid an "Access Denied" error when trying to save an image to, or open it from, a remote drive.

If Domain is empty, the local computer will be used to validate the specified username/password.

Using the optional Flag argument is generally not recommended.

Sub New(Width As Long, Height As Long, Optional Color )
Creates a blank image with the specified width and height. Closes a previously opened image, if any. This method is useful for creating a blank "canvas" for drawing graphics, text and other images. Color specifies the background color in HTML-style hexadecimal format, such as &HFFE055, 0 (black) by default.

See also: Section 6.1 - Image Drawing.

Sub Open(Path As String)
Opens a JPEG image for resizing. Path must be a physical path to the image.

See also: Section 2.1 - Thumbnail-Creating Steps.

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.

See also: Section 2.3 - Opening Images from Memory.

Function OpenInfo(Path As String) As Info
Obtains EXIF and IPTC metadata from an image specified by Path. Returns an instance of the Info object which is a collection of metadata fields. The collection may be empty if the image contains no metadata.

See also: Chapter 7 - Metadata.

Function OpenInfoBinary(ImageBlob As Variant) As Info
Same as OpenInfo but the image is opened from a binary memory source.

See also: Chapter 6 - Metadata.

Sub RemoveAlpha
Removes the current alpha channel from the image. Does nothing if the image has no alpha channel.

This method was introduced in version 2.1.

See also: Section 10.3 - Alpha Channel Management.

Sub ReplaceColor(OldColor As Long, NewColor As Long)
Assigns the color NewColor to all pixels of the given color OldColor. The old and new colors are to be specified as long integers with the most significant 8 bits set to Hex FF (&HFFxxxxxx), such as &HFFFF0000 (red), &HFF00FF00 (green), &HFF0000FF (blue), etc. This method was introduced by version 1.6.
Sub Rotate( Angle As Single, Color As Long)
Rotates the image to an arbitrary angle specified by Angle (in degrees.) A positive number specifies a counter-clockwise rotation, a negative number clockwise rotation. Color specifies the fill color for the four triangular corner areas formed by the rotation.

This method causes the Width and Height properties to increase as the image canvas has to expand horizontally and vertically to accommodate the slanted image. This method also adds an alpha channel to the image making the corner areas fully transparent. To take advantage of the alpha channel, the rotated image has to be saved in PNG format (PNGOutput property should be set to True.)

This method was introduced in version 2.3.

See also: Section 10.4 - Using PNG Format for Image Rotation.

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, .SendBinary, or .Binary.

See also: Section 4.4 - Image Flipping and Rotation.

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, .SendBinary or .Binary.

See also: Section 4.4 - Image Flipping and Rotation.

Sub Save(Path As String)
Resizes the currently opened image using parameters specified by various properties. Saves the resultant image thumbnail to a file specified by Path. If a file with this name already exists it will be overwritten.

See also: Section 2.1 - Thumbnail-Creating Steps.

Function SaveUnique(Path As String) As String
Same as Save but generates a unique filename if the file specified by Path already exists. A unique name is generated to avoid overwriting an existing file by appending a number in parentheses after the filename, such as image(1).jpg, image(2).jpg, etc.

Returns the filename (without the path) under which the image ends up being saved.

This method was introduced by version 1.7.

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

"attachment;filename=image_name.jpg"

You can only use this method in an ASP/IIS environment.

See also: Section 2.2 - Sending Thumbnails Directly to the Browser.

Sub Sepia(Hue As Double, Contrast As Double)
Applies the "Sepia" filter to an image which makes it look like an old photograph. Hue controls the brownish hue of the output image. Recommended range: 25 to 60. Contrast specifies the degree of contrast adjustment. Recommended range: 1.2 to 1.5.

This method was introduced in version 1.6.

See also: Section 4.7 - Sepia Filter.

Sub SetAlpha(Image As ASPJpeg, Inverse As Boolean)
Sets the alpha channel for the current image. Image must be another instance of the ASPJpeg object. It must be in the grayscale color space. To convert any image to grayscale, use the ToGrayscale method. The dimensions of Image must match that of the current image.

If Inverse is False, the pixel values of Image are used directly to form the alpha channel (0 corresponds to full transparency and 255 to full opacity.) If Inverse is True, the values are inverted.

If Image is Nothing (null), an alpha channel with all values set to 255 is created (or 0 if Inverse is True.)

An alpha channel only has effect if the image is saved in the PNG format (PNGOutput property is set to True.)

This method was introduced in version 2.1.

See also: Section 10.3 - Alpha Channel Management.

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, .SendBinary or .Binary.

See also: Section 4.2 - Image Sharpening.

Sub ToGrayscale(Method As Long)
Converts an image into the grayscale color space (1 byte per pixel.) Method specifies the conversion algorithm. Valid values: 0 (desaturation), 1 (recommended algorithm) and 2 (a slight variation of Method 1). Unlike the Grayscale method, reduces the number of bytes per pixel to 1. This method is useful for alpha channel management.

This method was introduced in Version 2.1.

See also: Section 10.3 - Alpha Channel Management .

Sub ToRGB
Converts a CMYK image into the RGB color space. Does nothing if the image is not a CMYK. Use this method to create Web-viewable RGB thumbnails of CMYK images. Note that it is more efficient to call this method after setting new Width and Height properties.

Note: Starting with version 1.7, this method also converts grayscale images to RGB.

See also: Section 8.1 - CMYK-to-RGB Conversion.


Advanced Image Management Advanced
Image Management
for ASP and .NET