Topic: imagedata.aspx file creating slow galleries

I have several galleries throughout this site: http://www.michaelskelley.com/weddings/ using a thumbnail and XML generator file. Sometimes the galleries seem to load fine, other times it will take up to 60 seconds. It doesn't seem to make a difference whether the page has been cached or what computer I am on. Is it a problem with the script? Is it a server issue? Recreating the site in PHP is not a desirable option, maybe a different ASP script?

Here is the code on the page:

<div id="flashcontent">SimpleViewer requires JavaScript and the Flash Player. <a href="http://www.macromedia.com/go/getflashplayer/">Get Flash.</a></div>
        <script type="text/javascript">
   
        var fo = new SWFObject("viewer.swf", "viewer", "100%", "100%", "8", "#ffffff");
       
        // SIMPLEVIEWER CONFIGURATION OPTIONS
        // To use an option, uncomment it by removing the "//" at the start of the line
        // For a description of config options, go to:
        // http://www.airtightinteractive.com/simp … tions.html
       
        fo.addVariable("xmlDataPath", "imageData.aspx");
        //fo.addVariable("firstImageIndex", "5");   
        //fo.addVariable("langOpenImage", "Open Image in New Window");
        //fo.addVariable("langAbout", "About");   
        fo.addVariable("preloaderColor", "0x666666");
       
        fo.write("flashcontent");   
    </script>   


And here is the script:

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Web" %>

<script language="VB" runat="server">

'
' imageData.aspx
' -----------------------
'
' by Tony Vincent - tony_vincent@hotmail.com
'
' DESCRIPTION
' -----------------------
' This script automatically generates the XML document for SimpleViewer (v1.5 and up).
' It detects all the images in the 'images' folder. Images are ordered by filename.
' Additionally, it now generates requisite thumbnails for files needing such the first
' time it is run.
'
' TO USE
' -----------------------
' 1) Place this file in the same folder as the SimpleViewer SWF.
' 2) Set your Image Album attributes below (path variables, maxImageDimension, title, etc).
' 3) Set the xmlDataPath in index.html:
'
'    in the object tag:
'        <param name=FlashVars value="xmlDataPath=imageData.aspx">
'
'    and in the embed tag:
'        ... FlashVars="xmlDataPath=imageData.aspx"/>
'

Sub Page_Load(Sender As Object, E As EventArgs)
   
    Dim imgPath as String = "images/"
    Dim thumbPath as String = "thumbs/"

    Dim xml as String
    Dim count as Integer
    Dim imgFiles As String() = Directory.GetFiles(Server.MapPath(imgPath))
    Dim imgFile As String

    xml = "<SIMPLEVIEWER_DATA maxImageDimension=""800"" textColor=""0xFFFFFF"" frameColor=""0x999999"" frameWidth=""4"" stagePadding=""0"" thumbnailColumns=""2"" thumbnailRows=""5"" navPosition=""right"" navDirection=""LTR"" title=""Engagements"" imagePath=""" & imgPath & """ thumbPath=""" & thumbPath & """>"

    For Each imgFile In imgFiles
        xml = xml & "<IMAGE>"
        xml = xml & "<NAME>" & Path.GetFileName(imgFile) & "</NAME>"
       
        ' OPTIONAL: Add auto captions using filename(s)
        'xml = xml & "<CAPTION>" & Path.GetFileName(imgFile) & "</CAPTION>"
       
        xml = xml & "</IMAGE>"

        ' Check for thumbnail & generate if it does not exist

        If Not File.Exists(Server.MapPath(thumbPath & Path.GetFileName(imgFile))) Then
            doImgThumb(imgPath & Path.GetFileName(imgFile), 120, 120, thumbPath, Path.GetFileName(imgFile))
        End If
   Next
   
    xml = xml & "</SIMPLEVIEWER_DATA>"
   
    ' Re-enforce proper output

    Response.Clear
    Response.ContentType = "text/xml"
    Response.Write("<?xml version=""1.0"" encoding=""UTF-8"" ?>" & xml)
   
End Sub


' -----------------------------------------------
'
'    doImgThumb(file,x,y,[path],[sfile])
'
'    PARAMETERS
'
'    file      Path/filename of image to load
'    x         Maximum thumbnail height
'    y       Maximum thumbnail height
'    path      Optional. Path to save thumbnail to
'    sfile   Optional. Filename of thumbnail to save
'   
'    DESCRIPTION
'
'    Basic .NET based thumbnail generator which
'    adheres to the .NET thumbnail library's
'    limitation of degraded image quality above
'    120x120 pixels. Aspect ratio maintained.
'    Omitting the optional parameters will stream
'    the jpeg thumbnail directly to the browser.
'
'    LICENSING
'
'    Although copyrighted material owned by the
'    Kennon Software Corporation, this particular
'    routine has been released to the public
'    domain for private or commercial use with
'    the single provision that this identifying
'    header and copyright notice remain with the
'    code.
'
'    (c) 2002-2005 Kennon Software Corporation
'          http://www.kennonsoft.com/
'
' -----------------------------------------------

Sub doImgThumb(pFileName, pHeight, pWidth, pSavePath, pSaveFile)
    Dim imgOrig, imgThumb As System.Drawing.Image
    Dim FileName As String
    Dim inp As New IntPtr()
    Dim width, height, imgWidth, imgHeight As Integer
    Dim rootpath, dosSavePath As String
    Dim bMakeDir As Boolean

    ' *** Setup
    bMakeDir = False

    If pSavePath <> Nothing and Len(CStr(pSavePath)) > 0 and Left(CStr(pSavePath),1) = "|" Then
        bMakeDir = True
        pSavePath = Right(pSavePath,Len(CStr(pSavePath)) - 1)
    End If

    If pSavePath <> Nothing and Len(CStr(pSavePath)) > 0 and Right(CStr(pSavePath),1) <> "\" Then
        pSavePath = pSavePath & "\"
    End If

    dosSavePath = Server.MapPath(pSavePath)

    ' *** Get File
    rootpath = Server.MapPath("./")
    FileName = rootpath & pFileName
    Try
        imgOrig = imgOrig.FromFile(FileName)
    Catch
        imgOrig = imgOrig.FromFile(rootpath & "error.gif")
    End Try

    ' *** Get Size (enforce max good thumbnail resolution of 120x120)
    If pWidth = Nothing Then
        width = imgOrig.Width
    ElseIf pWidth = 0 or CInt(pWidth) > 120 Then
        width = 120
    Else
        width = CInt(pWidth)
    End If

    If pHeight = Nothing Then
        height = imgOrig.Height
    ElseIf pHeight = 0 or CInt(pHeight) > 120 Then
        height = 120
    Else
        height = CInt(pHeight)
    End If

    ' *** Maintain Aspect Ratio
    Try
        imgHeight = imgOrig.Height
        imgWidth = imgOrig.Width
   
        If imgWidth > width Or imgHeight > height Then
            Dim deltaWidth As Integer = imgWidth - width
            Dim deltaHeight As Integer = imgHeight - height
            Dim scaleFactor As Double
   
            If deltaHeight > deltaWidth Then
                scaleFactor = height / imgHeight
            Else
                scaleFactor = width / imgWidth
            End If
   
            width = imgWidth * scaleFactor
            height = imgHeight * scaleFactor
        End If
    Catch
        imgOrig = imgOrig.FromFile(rootpath & "error.gif") ' Fetch error.gif
    End Try

    ' *** Resize - Pulls embedded thumbnail if exists, or creates an average quality scaled version
    imgThumb = imgOrig.GetThumbnailImage(width, height, Nothing, inp)

    ' *** Stream or Save
    If (pSavePath = Nothing or Len(CStr(pSavePath)) = 0) and (pSaveFile = Nothing or Len(CStr(pSaveFile)) = 0) Then

        Response.ContentType = "image/jpeg"
        imgThumb.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)

    Else
        If Len(CStr(pSavePath)) > 0 Then
            ' --- Path Specified
            If bMakeDir Then
                If Not Directory.Exists(dosSavePath) Then
                    Try
                        Dim di As DirectoryInfo = Directory.CreateDirectory(dosSavePath)
                    Catch e As Exception
                        'Failed
                    End Try
                End If
            End If

            If Directory.Exists(dosSavePath) Then
                If Len(CStr(pSaveFile)) > 0 Then

                    ' --- Path & Filename
                    imgThumb.Save(dosSavePath & pSaveFile, Imaging.ImageFormat.Jpeg)

                Else

                    ' --- Path Only, Use Orig Filename
                    imgThumb.Save(dosSavePath & pFileName, Imaging.ImageFormat.Jpeg)

                End If
            End If
        Else

            ' --- Path Not Specified
            imgThumb.Save(pSaveFile, Imaging.ImageFormat.Jpeg)

        End If
    End If

    ' *** Housekeeping
    imgOrig.Dispose()
    imgThumb.Dispose()

End Sub

</script>



Thanks in advance!