Show Script
Showing code for: includes/photolink.irev
Back
<?rev
-- File paths have to be relative to the includes folder
-- (where this file is), not to the actual web page.
function picSize pPic
put "../photos/" & pPic into tPicPath
-- ImageMagick command: identify pic.jpg
-- returns: pic.jpg JPEG 640x480 DirectClass 87kb 0.050u 0:01
put "identify " & tPicPath into tCmd
put shell(tCmd) into tSize
put word 3 of tSize into tSize
replace "x" with comma in tSize
return tSize
end picSize
-- captions.txt file has filename,caption - one record per line
function picCaption pPic
put "../data/captions.txt" into tPath
put URL ("file:" & tPath) into tCaptions
get lineOffset(cr & pPic & comma, cr & tCaptions)
if it = 0 then
put "Unknown" into tInfo
else
put item 2 to -1 of line it of tCaptions into tInfo
end if
return tInfo
end picCaption
-- assemble a list of all available photos
put "ls ../photos" into tCmd
put shell(tCmd) into tPhotoList
-- extract only the image files
put empty into tPhotoFiles
set the itemDel to "."
repeat for each line L in tPhotoList
put last item of L into tExt
if tExt is among the items of "jpg.jpeg.gif.png" then
put L & cr after tPhotoFiles
end if
end repeat
delete last char of tPhotoFiles
set the itemDel to comma
-- grab a random photo off the list
put any line of tPhotoFiles into tPic
-- assemble the html to show the selected photo
put picSize(tPic) into tSize -- returns width,height
put " width=" & quote & item 1 of tSize & quote & " height=" & \
quote & item 2 of tSize & quote into tSpecs
put "<img src=" & quote & "photos/" & tPic & quote & tSpecs & \
" alt=" & quote & tPic & quote & " />" into tPhotoLink
-- "put" sends the html back to the AJAX request
put tPhotoLink & "<br /><br />" & picCaption(tPic)
?>