|
Create a New ImageThe 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.) The Type Library ReferenceAs in the previous example,
the script contains a reference to the component's type library in a
<!-- 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 ObjectCreateImage 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 ImageThe 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") & _
"samples/tutorial/images/evening.jpg"),1,1
MergeWithImage takes five arguments:
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.
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") & _
"samples/tutorial/GeneratedImages/yellowsquare.gif")
Wrapping UpIt 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 Response.end 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. |