# philg-thumbnail-target.tcl
# created by philg@mit.edu on November 9, 2004
# roughly coded to the spec in http://philip.greenspun.com/images/index-file-generator-spec.txt
# this procedure displays an HTML page showing either the .3.jpg or .4.jpg version of a photo
# depending on a persistent cookie setting, then offers links to other sizes of images
proc philg_thumbnail_target {width_height_list_3 width_height_list_4 copyright_statement} {
# let's figure out what is in the file system first, e.g., if there is a RAW or a "plain old .jpg"
# that would be the original file from the camera
set pageroot [ns_info pageroot]
# full path name will always start with the page root, so we want to cut off the page root from
# head of the full_path_name string in order to get a full_url
set full_path_name [info script]
set full_url [string range $full_path_name [string length $pageroot] [expr [string length $full_path_name] - 1]]
set just_the_dir [file dirname $full_url]
set just_the_filename [file rootname [file tail $full_url]]
# if a point and shoot digital, could be just "foobar.jpg", otherwise some sort of RAW
set camera_raw_glob_pattern "${pageroot}${just_the_dir}/${just_the_filename}.{jpg,JPG,crw,CRW,cr2,CR2,orw,ORW}"
set available_raw_files [glob -nocomplain $camera_raw_glob_pattern]
# we have the full paths to the RAW files but now we want just the URLs so that we can
# serve links to those, i.e., we have to remove the pageroot directories
set available_raw_file_urls [list]
if {[llength $available_raw_files] > 0} {
foreach full_raw_path $available_raw_files {
if [regexp "${pageroot}(.+)" $full_raw_path match raw_url_stub] {
lappend available_raw_file_urls "$raw_url_stub"
}
}
}
if { [llength $available_raw_file_urls] > 0 } {
set camera_raw_offer_text " When reproducing images in print or making personal copies, consistent with the copyright policy, you will probably want to reproduce from the raw camera data:
[join $available_raw_file_urls "
"]"
} else {
# could not find any raw files
set camera_raw_offer_text ""
}
# we allow user to set a bunch of preferences
set cookie [ns_set get [ns_conn headers] Cookie]
# let's figure out if we are serving a big (.4) or medium (.3) JPEG
if { [string first "thumbnail_preference=4base_jpeg" $cookie] != -1 } {
# user has requested the big JPEGs
set img_tag "
"
set options "This image is available as a smaller JPEG."
set cookie_blurb "If this image doesn't fit on your screen you can change the default."
} else {
set img_tag "
"
set options "This image is available as a larger JPEG."
set cookie_blurb "If you have a very large monitor and would like to see larger photos every time you click on a small picture you can change the default."
}
ns_return 200 text/html "
$options
$cookie_blurb
All images on this server are copyrighted but in many cases may be reused with hyperlink credit. Please read http://philip.greenspun.com/copyright/ for standard terms.$camera_raw_offer_text