Getting Started
  What is ImgWriter?
  Features and Benefits
Quick Start
  Edit an Existing Image
  Create a New Image
  Save an Image in a Database
  The Image Collection Object

Programmer's Reference
  Object Model

  Installing ImgWriter

External Links
  ImgWriter home page
  Technical Support
  ImgWriter live demos
  SoftArtisans Home Page
  E-mail General Questions
  E-mail Technical Support

Create a New Image

The sample script createimage.asp uses the method CreateImage to create a new image. ImgWriter provides two additional methods that allow you to create new images: CreateGradientImage and CreateTwoWayGradientImage. (Note: You will find the original images for this and other samples in doc-samples\samples\tutorial\Images, and the generated images in doc-samples\samples\tutorial\GeneratedImages.)


[Run Sample] | [View Source]

The Type Library Reference

As in the previous example, the script contains a reference to the component's type library in a <!-- METADATA Type="TypeLib"--> directive, to enable access to the components public constants.

<!-- METADATA TYPE="TypeLib" UUID="{50D94450-589A-409B-819A-4F88B151C134}"-->

The UUID is a unique identifier for ImgWriter's type library.

Creating an Instance of the ImageGen Object

CreateImage is a method of the image generator object ImageGen. When you create an instance of ImageGen, it automatically creates an instance of the Font object, which the sample will use to customize text displayed on the image. To create an instance of ImageGen use,

Set objImageGen = Server.CreateObject("softartisans.ImageGen")

Creating an Image

The sample uses the method CreateImage to create a 200 by 200 yellow square:

objImageGen.CreateImage 200, 200, rgb(255,255,204)

CreateImage takes the image's width, height, and color as arguments.

MergeWithImage merges the yellow square with an existing image, evening.jpg:

objImageGen.MergeWithImage 20,80,Server.MapPath(Application("vroot") & _

MergeWithImage takes five arguments:

XDistance, in pixels, between the left border of the main image, and the left border of the image to merge with the main image.
YDistance, in pixels, between the top border of the main image, and the top border of the image to merge with the main image.
ImageThe file path and name of the image to merge with the main image.
OpacityLevel of opacity as a value between 0 and 1. At 0, the merged image is completely transparent. At 1, it is completely opaque.
TransColorThe color of the top (merged) image that will be made transparent when Opacity is set to a value less than 1.

We use DrawTextOnImage to add the title "Evening" to the image. To customize the font displayed, we create a Font object, and set the properties color, name, and weight:

Set objFont = objImageGen.Font
objFont.Color = rgb(0,0,221)
objFont.Name = "verdana"
objFont.Weight = 700
objImageGen.DrawTextOnImage 20, 50, 100, 1, "Evening"

*Note: The properties TextWidth and TextHeight can be used to determine precisely the required width and height parameters.

objImageGen.DrawTextOnImage 20, 50, objImageGen.TextWidth("Evening"), objImageGen.TextHeight("Evening"), "Evening"

The SaveImage method streams the image, as a GIF, to the browser, and presets a path and name for saving

objImageGen.SaveImage saiBrowser,saiGIF,Server.MapPath(Application("vroot") & _

Wrapping Up

It is considered good programming practice to explicitly release a reference to an object when it will no longer be used. Ending the ASP response prevents the transfer of extraneous additional characters with the image.

Set objImageGen = Nothing

Note that there is no HTML in loadimage.asp. The ASP page consists only of server-side script. This is important because the generated image is contained in a single ASP response. If you add other elements to the response, the image may be corrupted. When generating an image, do not include HTML or Response.Write lines.

Copyright © 2001-2004, SoftArtisans, Inc.