Working ok here
http://www.bookhamcragrats.co.uk/simpleviewer/ice.asp
Failing here
http://www.bookhamcragrats.co.uk/simple … ldwide.asp
Here is my aspx auto image cruncher file:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Web" %>
<script language="VB" runat="server">
'http://aspnet.4guysfromrolla.com/articles/012203-1.2.aspx
' *** Fix images with embedded thumbnails - Retain Hi Quality output and avoid pixilated output
'imgOrig.RotateFlip(RotateFlipType.Rotate180FlipNone)
'imgOrig.RotateFlip(RotateFlipType.Rotate180FlipNone)
'
' 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)
'Raw image file Path
'Dim imgPath as String = "../admin/pages/gallery-raw/General/"
Dim imgPath as String = "../admin/pages/gallery-raw/Chalk-climbing/"
'create optimised images from raw files
'Dim hiPath as String = "../admin/pages/gallery-raw/General/"
Dim hiPath as String = "../admin/pages/gallery-raw/Chalk-climbing/"
Dim thumbPath as String = "../admin/pages/gallery/chalk-climbing/thumb/"
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="""" textColor=""0xFFFFFF"" frameColor=""0xDADADE"" frameWidth=""10"" stagePadding=""10"" enableRightClickOpen=""true"" thumbnailColumns=""3"" thumbnailRows=""4"" navPosition=""left"" navDirection=""LTR"" title=""Chalk climbing..."" 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 hires image folder & generate ONCE only
If File.Exists(Server.MapPath(hiPath & Path.GetFileName(imgFile))) Then
doImgHi(imgPath & Path.GetFileName(imgFile), 800, 800, hiPath, Path.GetFileName(imgFile))
End If
' Check for thumbnail & generate ONLY if it does not exist
If Not File.Exists(Server.MapPath(thumbPath & Path.GetFileName(imgFile))) Then
doImgThumb(imgPath & Path.GetFileName(imgFile), 80, 80, 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
'
' doImgMed(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/
'
' -----------------------------------------------
' ##############################Create Hires images
Sub doImgHi(pFileName, pHeight, pWidth, pSavePath, pSaveFile)
Dim imgOrig, imgHi 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 and optimise / ignore if undersized
If pWidth = Nothing Then
width = imgOrig.Width
ElseIf imgOrig.Width = 0 or imgOrig.Width > 800 Then
width = 800
ElseIf imgOrig.Width = 0 or imgOrig.Width < 800 Then
width = imgOrig.Width
Else
width = CInt(pWidth)
End If
If pHeight = Nothing Then
height = imgOrig.Height
ElseIf imgOrig.Height = 0 or imgOrig.Height > 800 Then
height = 800
ElseIf imgOrig.Height = 0 or imgOrig.Height < 800 Then
height = imgOrig.Height
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
' *** Fix images with embedded thumbnails - Retain Hi Quality output and avoid pixilated output
imgOrig.RotateFlip(RotateFlipType.Rotate180FlipNone)
imgOrig.RotateFlip(RotateFlipType.Rotate180FlipNone)
' *** Resize - Pulls embedded Medimage if exists, or creates an average quality scaled version
imgHi = imgOrig.GetThumbnailImage(width, height, Nothing, inp)
' *** check file dimension H and W is bigger than or = to 800px then save / or abort
If (imgOrig.Height = 0 or imgOrig.Height > 800) or (imgOrig.Width = 0 or imgOrig.Width > 800) Then
' *** Stream or Save
If (pSavePath = Nothing or Len(CStr(pSavePath)) = 0) and (pSaveFile = Nothing or Len(CStr(pSaveFile)) = 0) Then
Response.ContentType = "image/jpeg"
ImgHi.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
ImgHi.Save(dosSavePath & pSaveFile, Imaging.ImageFormat.Jpeg)
Else
' --- Path Only, Use Orig Filename
ImgHi.Save(dosSavePath & pFileName, Imaging.ImageFormat.Jpeg)
End If
End If
Else
' --- Path Not Specified
ImgHi.Save(pSaveFile, Imaging.ImageFormat.Jpeg)
End If
End If
'end of only execute if too big
End If
' *** Housekeeping
imgOrig.Dispose()
ImgHi.Dispose()
End Sub
' ########################### create thumbs next
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
' *** ORIGINAL Get Size (enforce max good thumbnail resolution of 120x120)
If pWidth = Nothing Then
width = imgOrig.Width
ElseIf pWidth = 0 or CInt(pWidth) > 80 Then
width = 80
Else
width = CInt(pWidth)
End If
If pHeight = Nothing Then
height = imgOrig.Height
ElseIf pHeight = 0 or CInt(pHeight) > 80 Then
height = 80
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
' *** Fix images with embedded thumbnails - Retain Hi Quality output and avoid pixilated output
imgOrig.RotateFlip(RotateFlipType.Rotate180FlipNone)
imgOrig.RotateFlip(RotateFlipType.Rotate180FlipNone)
' *** Resize - Pulls embedded Medimage 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>