Description of "sold.asp"

This script is called from the <img> tag and generates a compound JPG image. The listing is shown below:

Response.Expires = 0
Response.Buffer = true

Set Image = Server.CreateObject("csImageFile.Manage")

Image.ReadFile Server.MapPath("images/car.jpg")
Image.Transparent = true
Image.TransparentColor = "ffffff"
Image.MergeBack Server.MapPath("images/sold.png"), 0, 0

Response.ContentType = "image/jpeg"
Response.BinaryWrite Image.JPGData

The first 3 lines prevent the page from caching. This is recommended when creating images using ASP.

Then we create an instance of the csImageFile object. If you are using the trial component you must replace "csImageFile" with "csImageFileTrial".

Next we read the original image into csImageFile. The parameter is the physical path and file name of the original jpg image and Server.MapPath is used to find this path. The image is in a sub directory called "Images". You can hard code the full path if you know it but the method shown will work if the script is moved on the server.

Then we use the MergeBack command to put the "stamp" over the image. In this case the stamp is a PNG image with a white background. By setting Transparent to true and the TransparentColor to white this background will be transparent. The MergeBack command can detect the transparency settings of a PNG or GIF if they have been saved in the file. This includes alpha transparency of a PNG.

Finally, we stream the image to the browser in JPG format. It is important to set the content type. Internet Explorer will display the JPG correctly without it but other browsers, might have problems.

The stamp could have been drawn instead of using the Merge command because it is simply two lines and a piece of text. The technique shown here will work with a more complex foreground image, including a PNG with alpha transparency.