The image component is a COM object DLL that allows ASP code to:
The following example shows how to open an image and just obtain it's size:
The library does not decompress the image unless the image is buffer is touched, either by ChangeSize(), SaveJpgImage(), or TextBox(). Once the image buffer is touched, the original image is decompress into memory and retained until the Image object is destroyed or until Close() is used. This is important since image buffers can be large. General Image object methods and properties are:
Text image object methods and properties are:
EXIF Image methods and properties:
1. Make a directory and copy the "SImageUtil.dll" into it. 2. Install the SImageUtil.dll by running "regsrv32 SImageUtil.dll" Boolean which indicates if file names provided to OpenImageFile(), SaveJpgFile(), and Thumb() methods are either IIS filenames or physical filenames. The default for this value is 'false' which is IIS filenames. Remarks: When using IIS filenames (false) the filename path separator is a foreword slash '/', the path starts at the root of the website, and may contain IIS virtual directories. This is the same style of filename that appears in a HTML hyperlink. When using an IIS name relative filenames are allowed from the current ASP page. IIS filenames are limited to filenames that appear on the local web site. When using physical filenames (true) the filename path separartor is a backslash, may contain a local driver letter or server name, and starts at the root of the drive/device. This is the type of filename typically used in windows. When using a physical path the entire filename must be specified. Example: The following example opens an image in the preview sub-directory:
The following example opens a image in the "C:\Images" directory on the server:
If you set the PhysicalPath to true on an Image object you can always set it back to false to use IIS paths, or you can perform the conversion from an IIS pathname to a physical one in your ASP code directly. For example, the following opens the same file as the first example but does so when using physical paths instead of IIS paths.
The primary reason to set PhysicalPath to true is to be able to specify filenames that are outside the website.
Boolean which indicates if error text is to be automatically written to the IIS output. The default for this value is TRUE. Remarks: When an error occurs by default the SImageUtil component will output error test to the IIS output stream. If you set this value to FALSE this will not occur. In either case, the last error message that was generated is available as LastError.
A string that contains the last error message. The message is per open interface instance (e.g., the Image handle). Remarks: If no error has occurred in the open interface instance this value is an empty string. If an error has occurred, this string contains the error message that was generated. Note this value may be reset to an empty string when this occurs in order to detect the next failure if needed. Example: The following example opens an image and checks to see if the operation caused an error.
Opens an image file. Syntax: Parameters:
Remarks: This function opens an image file and reads the image's attributes (such as width and height). It does not decompress or read the image itself. The image is decompress when the image buffer is first accessed. The ImageName is a local URL style path name or a physical pathname based on the PhysicalPath setting. The default is a local URL style name. Currently only JPEG, GIF and BMP image file formats are supported. Example: The following example reads the image's width and height.
The Width and Height properties are read-only properties that returns the image's current width and height. When the image is first opened the Width and Height are that of the original image. If the image size is changes, the Width and Height are the new image's size. Example: The following example reports the image's width and height after changing its size.
By default a change size operation will not allow either vertices of an image to be enlarged over the original image's size. To disable this, set this property to true. Example:
Note that the AllowEnlarge property can be set on the image object at any time. An image does not have to be opened to set this property.
By default a change size operation will not allow either vertices of an image to be changed disproportionate to one another. To disable this, set this property to true. Example: The follow example reads the image's width and height.
Note that the KeepAspect property can be set on the image object at any time. An image does not have to be opened to set this property.
This function changes the size of the image. Syntax: Parameters:
Remarks: By using ChangeSize() the image buffer will be decompressed if not already done so. Once the image buffer is decompressed it remains in memory until the Image object is destroyed or until a Close() is performed. ChangeSize() creates a new image buffer from the original image and this becomes the new image for the object. The size of the new image will be bounded by the current AllowEnlarge and KeepAspect property settings. Reading Width and Height after calling ChangeSize() will yield the actual width and height of the new image. Example: The following example creates a thumbnail from the image
Since ChangeSize() always creates the new image from the original image, it can be used to create more then one image at a time without lose of quality due to multiple sizing operations. This can be useful in removing decompression steps (which can be time consuming). For example, the following to sequences yield the same results but the first is quicker:
Saves the current image as a JPEG file. Syntax: Parameters:
Remarks: The current image is compressed based on the Quality setting and saved to ImageName. Note that SaveJpgFile() will create the entire directory tree to the destination filename if it does not already exist. If the destination ImageName file already exists, it will be replaced. The ImageName is either a local URL path name or a physical pathname as determined by the PhysicalPath setting. The default is a local URL path name. Note if you put text on the image with TextBox() you will likely want a very high quality setting when saving in JPEG format. Example: The following example creates a copy of the image with a lower then normal quality setting.
Closes the opened image file and release any associated memory for the image. Syntax: Remarks: There is an implicit close when the Image object is destroyed; however, depending on the size of the source image uncompressed image buffers can be quite large and if the image is no longer needed a Close() can be perform to free memory right away.
Crops the image. Syntax: Parameters:
Remarks: This functions crops the image such that the new image contains the image formed by the rectangle X,Y,X+DX,Y+DY of the original image. Example: Pull out a 100 x 100 image from the center of the original and then save it.
Returns the pixel value at the selected coordinates. Syntax: Parameters:
Remarks: This function is not used by ASP but is instead used by other C++ components. It returns the 24 bit RGB value of the selected pixel.
The do-it-all function. Creates the DstImage from the SrcImage if the DstImage does not already exist. Syntax: Parameters:
Remarks: This function first checks to see if DstImage exists. If such a file exists, no further operation is performed and control is returned to the running script. If DstImage does not exist, the function opens the SrcImage with OpenImageFile(), applies a ChangeSize() on it for NewWidth and NewHeight, and then a SaveJpgImage() with Quality, and finally a Close(). This sequence is performed on at most one thread at a time on the local server as to not swamp the server. (E.g., if multiple threads call Image.Thumb() currently for DstImage's that do not exist, they will be decompressed, sized, recompressed and saved one a time. Serialization only occurs if the DstImage does not exist). The current set rules for AllowEnlarge and KeepAspect are used during the ChangeSize(), and the PhysicalPath setting determines the SrcImage and DstImage pathname type. Example: Make sure we have the preview image, else create it.
Draws text on the image. Syntax: Parameters:
Remarks: The Text is formatted and fitted into a box. The entire box of text is then placed on the image according to Position. The background color of the box is set with SetBoxColor() and may be set to any color and opacity - including clear (e.g., no background). The color of the text defaults to SetTextColor(), and again may be set to any color and opacity. In addition, the color of the text can also be controlled with a <font> tag in the Text string. The Text string may include the following escape sequences:
The Text string may include the following tagged modifiers:
The <font> tag may include the following attributes:
The default font and colors are: Arial 10 pts black with a 60% white background. The colors available by name are: black, white, red, green, blue, yellow, magenta, cyan, gray, darkred, darkgreen, darkblue, lightbrown, darkmagenta, daycyan. The Position argument is used to determine the relative position of the text on the image. The TextBox() function automatically determines the absolute drawing position based on the size of the text being drawn and the Position selected. There are nine positions:
A ChangeSize() will erase the text draw on the image. All text must be drawn after the size of the image has been changed (if the size is being changed). Examples: Example of position:
Example of formatting and alignment::
Example of font tag:
Note: You can only use fonts that are installed on the server (or whatever machine you are running your code from). Supplying a font name that does not exist will cause the system to pick a default font for your.
The number of pixels between the text box and the image. The default is 5. Examples: Example shows setting the BoxMargin to zero before putting text at position #8 causing no margin between the text and the edge of the image.
Sets the color of the text box. Syntax: Parameters:
Examples: The following images show a different background opacities for a white and black background. // Black background,
white text sample
Note that 0% opacity is no background, and 100% opacity is a solid background.
The number of pixels between the text and the text box. The default is 3. Examples: The example shows a TextMargin of 0 and 10.
Sets the color of the text. Syntax: Parameters:
Remarks The SetTextColor() function can also be performed with the <font> tag in the text being displayed. Examples:
Returns the requested Exif tag. Syntax: Parameters:
Remarks This function returns the requested Exif information as a string. If the Exif information is not found, then an empty string is returned. The ShortName is formatted as: Prefix.Name. Where Prefix is "Main.", "Sub.", an OEM ID, or "". Following the Prefix is the name of the requested field. Each prefix has its own list of possible fields that are currently understood by simageutil. "Main" and "Sub" fields are standardized Exif tags that many camera manufactures supply. An OEM specific prefix are fields that are specific to an OEM type. A field with a prefix is an internally produced field that simageutil creates from the Main, Sub, and OEM prefixes that it found. This makes life a lot easier for displaying common data as these fields. The comprehensive list of fields that are understood are in the Exif.cpp source file. To get a listing of the Exif fields that your camera is providing use DumpExif(). If Name (of Prefix.Name) is a number then that is a tagged field that simageutil doesn't not understand. You can still obtain the field with GetExif() by using the ShortName as it appears in DumpExif(). For more information see the Exif notes and web sample page. Example:
Returns the requested Exif tag. Syntax: Remarks This function dumps all the found Exif information from the image to the HTML output device. This function is used for debugging. Refer too the Exif notes and web sample page to see a sample output from this function. Example:
|