Description of "showresults.asp"

The form data is poated to "showresults.asp" which uses csASPUpload to read the data. If it contains an uploaded file it will read this and pass it to csASPGif, or csASPGif will read the file from the remote URL. The check box is also read so that the UnOptimize method can be called if required.

The GIF is saved into a session variable for future use, although it could be saved to a temporary file instead. If an image is stored in a session variable in this way it is important to clear it immediately after use rather than allowing it to stay in memory for the duration of the user session.

Here is the code that reads the GIF file:

<%
Set Gif = Server.CreateObject("csASPGif.Gif")
Set Upload = Server.CreateObject("csASPUpload.Process")
On Error Resume Next
  If Upload.FileQty = 0 Then
    Gif.ReadURL Upload.Value("URL")
  Else
    Gif.ReadStream Upload.FileData(0)
  End If
If Err = 0 Then
  If Upload.Value("Unoptimize") = "true" Then
    Gif.UnOptimize
  End If
  Session("GIF") = Gif.GIFData
End If
Err.Clear
%>

Errors will be generated if no GIF is supplied or if the file is in the wrong format. To ensure graceful failure On Error Resume Next is used and the session variable is only set if a GIF was read.

The next working part of the script is in the body of the page. The frame count and colour depth is extracted and displayed. Then each frame is displayed using a loop. Finally, the session variable is cleared.

<%
If Gif.FrameCount = 0 Then
  Response.Write "<p>No image loaded.</p>"
Else
  Response.Write "<p>Frame count: " & Gif.FrameCount & " .</p>"
  Response.Write "<p>Colour Depth: " & Gif.ColorDepth & "</p>"
  Response.Write "<table>"
  For I = 0 To Gif.FrameCount - 1
    Response.Write "<tr><td>Frame " & I & "&Time=" & CDbl(Now) & "</td>"
    Response.Write "<td><img src=""gifstream.asp?Frame=" & _
      I & """></td></tr>"
  Next
  Response.Write "</table>"
End If
Session("GIF") = nothing
%>

The loop writes out an <img> tag for each frame in the GIF. The SRC attribute is another ASP script that streams the frame specified by the index, passed in the query string parameter. This script, called "gifstream.asp" uses the session variable that was stored earlier. An extra variable has been added to the URL by converting the current time to a real number. This prevents the caching that can occur when the demo is run a second time.

<%
Response.Expires = 0
Response.Buffer = true
Response.Clear
Set Gif = Server.CreateObject("csASPGif.Gif")
Gif.ReadStream Session("GIF")
Response.ContentType = "image/gif"
Response.BinaryWrite Gif.GIFFrameData(Request.QueryString("Frame"))
%>

By using the session variable to hold the image, the image only needs to be loaded once. We have shown how to obtain the file from a remote URL or by uploading, so that it can be an interactive demo. The image could be read from a local path using the ReadFile command, and this demo is supplied with an alternative script that uses this method.

More information on our csASPUpload component.

Return to the start.