Coders Corner / ASP Thumbnail Galleries
What do YOU think about this Script? Add YOUR comments at the end!
I’m very interested in running VBScript on my ASP pages. While I know most of you run some flavor of Unix, I prefer Microsoft Windows NT/2000 with IIS 4/5.What do YOU think about this Script? Add YOUR comments at the end!
I’m very interested in running VBScript on my ASP pages. While I know most of you run some flavor of Unix, I prefer Microsoft Windows NT/2000 with IIS 4/5. I’ve written all my ASP pages and scripts myself, including this cool VBScript that you can use to automate the creation of thumbnail galleries. The only thing you will have to do is create some thumbnail pictures and put them in a different directory than your “large” pictures. The script will find all pictures and create galleries for you. If you have new pictures, or additions to a certain gallery, just place the pictures in the directory, and you’re done!
How It Works
I’m using the File System Object (FSO) to open a the directory containing the files and list them all. (Function GetFiles) Second I create the HTML line for the thumb and link. (e.g. <a href=”\mypics\myfile.jpg” target=”_blank”><img src=”\mypics\thumbs\tn_myfile.jpg”></a>) All these links are put in an array. (Function CreatePictureArray) Then I calculate how many galleries are needed to display all thumbs. You do not want a gallery with 523 thumbs do you? So I check how many thumbs you want on one page, and so calculate the number of galleries needed. (Function HowManyTables).
The Sub DrawTable puts the table on the screen. It uses the gallerynumber to check what pictures to display. The DrawLinks Sub will create the |<, <, > and >| icons at the bottom. They can be used to navigate through the galleries. It uses the ?g= paramter in the URL to navigate. (e.g. http://mydomain.com/thumb4.asp?g=5 to see the 5th gallery) It would be quit nasty to have your webserver check the whole directory at every hit. Therefore stuff that you need on all pages (the PictureArray etc.) will be put in a Session variable the first time you access the page. This way it will be available to the user throughout the entire session. If you have a really loaded webserver with numerous hits/seconds you might consider using Application variables instead of the Session variables. Remember, if you do that and you add more pictures, you will have to restart the web application!
At the bottom you see the actual call to it all. If the ?g= is empty, this is the first time the script is run. Therefore it will scan your pictures directory and set the Session parameters in BuildSession. Otherwise it will just display the gallery the user wanted by using the DrawTable and DrawLinks Subs. Have fun!
There are a few easily understood parameters in the script that must be changed:
WebPath : Where does the WEB start physically on the drive
Picture Path: Where are the larger images relative to the WebPath
WebPicture Path : What’s the relative path to the pics in the Web
WebThumbPath: Where did ya hide the thumbs
ThumbPrefix: What is the prefic for thumbnail pics
TargetFrame: In what targetframe should the large images load
TableWidth: How many thumbs in a row
TableHeight: How may rows in a table
TotalTableWidth: Width (in pixels) of the table
Copy the script below, and save it in a text document as THUMBS4.ASP
”””””””””””””””””””””””””””””””””””””””””””””””””””
Function GetFiles (Path)
Dim fso, folder
Set fso = CreateObject (“Scripting.FileSystemObject”)
Set folder = fso.GetFolder (Path)
Set GetFiles = folder.Files
End Function
Function CreatePictureArray (FilesList, WebPicPath, WebThPath, ThPrefix, TarFrame)
Dim pcounter, returnarray ()
ReDim returnarray (FilesList.Count)
pcounter = 0
For Each File in FilesList
returnarray (pcounter) = “target='” & TarFrame & “‘>File.Name & “‘>”
Next
CreatePictureArray = returnarray
End Function
Function HowManyTables (FilesList, TbWidth, TbHeight)
Dim addition
If (FilesList.Count / (TbWidth * TbHeight)) Int (FilesList.Count / (TbWidth * TbHeight)) Then
Else
addition = 0
End If
HowManyTables = (Int (FilesList.Count / (TbWidth * TbHeight))) + addition
End Function
Sub DrawTable (TableNumber, PicArray, TbWidth, TbHeight, TotalWidth)
Dim currentpicture, rcounter, ccounter, width
width = TotalWidth / TbWidth
‘ Response.Write “”
Response.Write “”
If currentPicture > UBound (PicArray, 1) Then
‘ Nothing
Else
Response.Write “”
If currentpicture > UBound (PicArray, 1) Then
‘ Response.Write “.”
Response.Write “.”
Else
‘ Response.Write “” & PicArray (currentpicture) & “”
Response.Write “” & PicArray (currentpicture) & “”
‘ Response.Write “” & currentpicture & “”
End If
Next
Response.Write “”
End If
Next
Response.Write “”
Response.Write “”
End Sub
Sub DrawLinks (TableNumber, TotalTables)
Response.Write “”
Response.Write “|<”
Response.Write ” ”
Response.Write “”‘><”
Response.Write ” ”
Else
Response.Write “|<”
Response.Write ” ”
Response.Write “<”
Response.Write ” ”
End If
If Int(TableNumber) < TotalTables Then
Response.Write “”‘>>”
Response.Write ” ”
Response.Write “>|”
Response.Write ” ”
Else
Response.Write “>”
Response.Write ” ”
Response.Write “>|”
Response.Write ” ”
End If
Response.Write “”
End Sub
Sub BuildSession
Dim WebPath, PicturePath, WebPicturePath, WebThumbPath, ThumbPrefix,
TargetFrame, TableWidth, TableHeight, TotalTableWidth
WebPath = “C:\InetPub\WWWRoot\PornStartsHere\”
PicturePath = “Pics\Hardcore\”
WebPicturePath = “Pics/Hardcore/”
WebThumbPath = “Pics/Hardcore/Thumbs/”
ThumbPrefix = “tn_”
TargetFrame = “_blank”
TableWidth = 4
TableHeight = 5
TotalTableWidth = 400
Set Session(“files”) = GetFiles (WebPath & PicturePath)
Session (“PictureArray”) = CreatePictureArray (Session (“files”),
WebPicturePath, WebThumbPath, ThumbPrefix, TargetFrame)
Session (“TableWidth”) = TableWidth
Session (“TableHeight”) = TableHeight
Session (“TotalTableWidth”) = TotalTableWidth
Session (“tables”) = HowManyTables (Session (“files”), TableWidth,
TableHeight)
‘ Response.Write “——- Building Session ——-”
‘ Response.Write “Session Files: ” & Session (“files”).Count & “”
‘ Response.Write “Picture Array: ” & UBound (Session (“PictureArray”), 1) &
“”
‘ Response.Write “Tables: ” & Session (“tables”) & “”
‘ Response.Write “——– Session Built ———“
End Sub
”””””””””””””””””””””””””””””””””””””””””””””””””””
Dim gallery
If Request(“g”) = “” Then
BuildSession
Else
gallery = Request (“g”)
End if
‘Response.Write “——– Session Variables ——”
‘Response.Write “Session Picture Array: ” & UBound (Session
(“PictureArray”), 1) & “”
‘Response.Write “Session TableWidth: ” & Session (“TableWidth”) & “”
‘Response.Write “Session TableHeight: ” & Session (“TableHeight”) & “”
‘Response.Write “Session Tables: ” & Session (“tables”) & “”
‘Response.Write “———————————”
‘Response.Write “You want gallery ” & gallery & “”
Response.Write “Table ” & gallery & “”
DrawTable gallery, Session (“PictureArray”), Session (“TableWidth”), Session
(“TableHeight”), Session (“TotalTableWidth”)
DrawLinks gallery, Session (“tables”)
Response.Write “”
”””””””””””””””””””””””””””””””””””””””””””””””””””
%>
[ MORE SCRIPTS | CODER’S CORNER >>
Reader Comments on this Article:
Comment by:Summary:
StephenGreat to see some NT/ASP stuff
hgjjh
PsylockeTried the script, but it does nothi…