Description of the ASP Multipage TIFF demo

There are two scripts used in this demo. "tifdemo.asp" is the HTML page that controls the navigation and acts as a placeholder for the image. "showtif.asp" loads the image and streams it to the browser.

tifdemo.asp

Most of the VBScript code is at the start of the script and it finds the number of pages and records the current page:

<%
Response.Expires = 0
Response.Buffer = true
Response.Clear

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

TIFPath = "multipage.tif"
TIF = Server.MapPath(TIFPath)
PageCount = Image.ImageCount(TIF)
If Request.QueryString("Page") = "" Then
  CurrentPage = 1
Else
  CurrentPage = Request.QueryString("Page")
  If Not IsNumeric(CurrentPage) Then
    CurrentPage = 1
  Else
    If CurrentPage < 1 Then
      CurrentPage = 1
    End If
    If CInt(CurrentPage) > CInt(PageCount) Then
      CurrentPage = PageCount
    End If
  End If
End If
%>

The ImageCount method in csImageFile is used to read the number of pages in the TIFF. It needs the physical path to the file, which is found using Server.MapPath. The rest of the code sets the CurrentPage variable by reading the URL variable that is passed by the links later in the page. If the URL variable is an empty string, not a number or outside the range of valid numbers, the CurrentPage variable is set accordingly. Note that CInt is used when the two variables are compared so that they are compared as numbers, not strings.

The next working part of the script is in the body of the page. The formatting has been kept to a minimum and there is no attempt to hide invalid links, such as the Previous link when the first page is displayed. The listing does not show the line breaks.

Page Number: <%= CurrentPage %> of <%=PageCount%>
<a href="tifdemo.asp?Page=1">First</a>
<a href="tifdemo.asp?Page=<%= CurrentPage - 1%>">Previous</a>
<a href="tifdemo.asp?Page=<%= CurrentPage + 1%>">Next</a>
<a href="tifdemo.asp?Page=<%= PageCount %>">Last</a>
<img src="showtif.asp?Page=<%= CurrentPage %>&Path=<%= TIFPath %>">

The current page and the relative path to the TIFF are passed to the image generation script as URL parameters.

"showtif.asp"

This code reads the URL parameters passed from "tifdemo.asp". It sets the ReadImageNumber property and then loads the file. Only the page specified by ReadImageNumber is loaded. The ColorDepth property is checked to determine which format to use when streaming the image to the browser. For colour depths of 8 bits or less a GIF can display the image without losing any image quality. For higher colour depths the JPG format is used. This conditional code could be left out and one or other format used regardless of the colour depth.

<%
Response.Expires = 0
Response.Buffer = true
Response.Clear

Set Image = Server.CreateObject("csImageFile.Manage")
Image.ReadImageNumber = Request.QueryString("Page")
Image.ReadFile Server.MapPath(Request.QueryString("Path"))
If Image.ColorDepth > 8 Then
  Response.ContentType = "image/jpeg"
  Response.BinaryWrite Image.JPGData
Else
  Response.ContentType = "image/gif"
  Response.BinaryWrite Image.GIFData
End If
%>

Return to the demo.