ImgWriter can be used to insert an image into a web page in two different ways:
- Use an <IMG> tag with a "src" attribute that points to the image itself, after you have used ImgWriter to generate the image and save it to your server.
- Use an <IMG> tag with a "src" attribute that points to an asp page that generates the image and streams it to the browser. In this case, the image is sent to the browser without first being saved to the file system.
Saving the ImgWriter generated image to disk before insertion:
This simply involves keeping track of where the image is saved on the server and then providing the URL for that location in your <IMG> tag.
<%@ Language=VBScript %>
<!--METADATA TYPE="TypeLib"
UUID="{50D94450-589A-409B-819A-4F88B151C134}" -->
<%
Dim objImageGen
Dim strPath
strPath = Server.MapPath("./Images/truck.jpg")
Set objImageGen = Server.CreateObject("softartisans.ImageGen")
'---Load the original file
objImageGen.LoadImage strPath
'--- Create a thumbnail, 50 pixels in height
objImageGen.CreateThumbnail , 50
'---***Before saving the file to c:\myWebDir\resize.jpg, make sure that
'---you have adequate NTFS permissions for your IIS user account
objImageGen.SaveImage saiFile, saiJPG, "c:\myWebDir\resize.jpg"
%>
<TABLE border = '1'>
<TR>
<TD>Image</TD>
</TR>
<TR>
<TD><IMG src='./resize.jpg'></TD>
</TR>
</TABLE>
Retrieving a dynamically generated image:
This requires two pages: the HTML page containing the <IMG> tag and the ASP page to which the <IMG> tag points.
The HTML:
Here the <IMG> tag has its "src" attribute set to the URL of the asp page that will dynamically generate an image and stream it to the browser. Please note that depending on the size of the image, the BufferResponse property may need to be set to "true" in order for this to be effective. (For more on this topic, please see KB article: http://support.softartisans.com/kbview.aspx?ID=701).
<HTML>
<BODY>
<TABLE border='1'>
<TR>
<TD>Image:
</TD>
</TR>
<TR>
<TD> <IMG src='http://myServerName/GenerateImage.asp'>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
The ASP code: (GenerateImage.asp)
The function of this ASP code is to generate an image, and nothing else. This asp code cannot contain any HTML, since the request for this code will be made from the "src" attribute of an <IMG> tag.
<%@ Language=VBScript %>
<!--METADATA TYPE="TypeLib"
UUID="{50D94450-589A-409B-819A-4F88B151C134}" -->
<%
Option Explicit
Dim saImg
Set saImg = Server.CreateObject("SoftArtisans.ImageGen")
'--- added in v1.1.6
saImg.BufferResponse = "true"
'--- Load the Image File
saImg.LoadImage "C:\Resize.jpg"
'--- Do whatever you want to the image here,
'--- like thumbnailing, then save to the browser.
saImg.CreateThumbnail 100,100, saiBicubic
saImg.SaveImage saiBrowser, saiJPG, "Resize.jpg"
%>
Related Topics:
|