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
Response.Clear

Set Image = Server.CreateObject("csImageLite.ImageFunctions")

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"
Image.StreamToBrowser "jpg"
%>

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

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

Next we read the original image into csImageLite. 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 although some browsers will display correctly without the content type.

A piece of text could have been drawn on the image instead of merging. The technique shown here will work with a more complex foreground image, including a PNG with alpha transparency.

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.