#!/bin/sh
# -*-tcl-*- \
exec tclsh "$0" ${1+"$@"}
#
# $Id: browse.cgi,v 1.6 2005/05/10 14:00:53 cinsk Exp $
#
#
# Images per line on thumbnail mode.
#
set img_per_line 4
#
# Images per page on thumbnail mode.
#
set img_per_page 12
#
# Set verbose mode on/off, affects on command line mode
#
set verbose_mode 1
#
# Thumbnail width.
#
set thumbnail_width 120
#
# Image information -- To hide the information of each image,
# set this variable to zero.
#
set use_identify 1
#
# Set debug mode
#
set debug_mode 0
package require ncgi
::ncgi::parse
set cwd [::ncgi::value cwd .]
#
# Commands to get the image list
#
set img_list [exec find $cwd -path "*CVS*" -prune -o -path "*.thumbnails" -prune -o -path "*.xvpics*" -prune -o \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.gif" \) -print]
if {[info exists env(GATEWAY_INTERFACE)] &&
[regexp "^CGI/.*" $env(GATEWAY_INTERFACE)]} {
set cgi_mode 1
} else {
set cgi_mode 0
}
if {$debug_mode != 0} {
set table_border 1
} else {
set table_border 0
}
proc get_thumb_filename {img_file} {
set dirname [exec dirname $file]
set filename [exec basename $file]
if {! [file exists ${dirname}/.thumbnails/${filename}]} {
return ${dirname}/.thumbnails/${filename}
}
return $img_file
}
proc proc_gen_thumbs {} {
global img_list verbose_mode thumbnail_width
foreach file $img_list {
if {[file type $file] != "file"} { continue }
set dirname [exec dirname $file]
set filename [exec basename $file]
if {! [file exists ${dirname}/.thumbnails]} {
file mkdir ${dirname}/.thumbnails
}
if {! [file exists ${dirname}/.thumbnails/${filename}]} {
if {$verbose_mode != 0} { puts "Generating thumbnail for $file..." }
exec convert -resize ${thumbnail_width}x10000 $file ${dirname}/.thumbnails/${filename}
}
}
}
proc proc_thumbnails {} {
global img_list img_per_page img_per_line
global table_border cwd
set page [::ncgi::value page 1]
set page_cnt [expr [llength $img_list] / $img_per_page]
set start [expr ($page - 1) * $img_per_page]
set end [expr $start + $img_per_page - 1]
if {[llength $img_list] % $img_per_page != 0} {
incr page_cnt
}
proc_header
# puts "page = $page, start = $start, end = $end
"
puts "
Page $page of $page_cnt, Total [llength $img_list] image(s)
" set img_list [lrange $img_list $start [expr $end]] puts "" if {$page > 1} { puts "\[ Previous \] " } else { puts "\[ Previous \] " } puts "\[ Up \] " if {$page < $page_cnt} { puts "\[ Next \] " } else { puts "\[ Next \] " } puts "
" set cnt 0 puts "" foreach file $img_list { if {[file type $file] != "file"} { continue } set dirname [exec dirname $file] set filename [exec basename $file] if {$cnt == 0} { puts "" if {[info exists prev]} { set page [expr ($index - 1) / $img_per_page] if {$page <= 0} { set page 1 } puts "\[ Previous \] " } else { puts "\[ Previous \]" } puts "\[ Thumbnails \] " if {[info exists next]} { set page [expr ($index + 1) / $img_per_page] if {$page <= 0} { set page 1 } puts "\[ Next \] " } else { puts "\[ Next \]" } puts "
" if {[file exists $file.desc]} { puts [exec cat $file.desc] } puts "" if {$use_identify != 0} { puts "[exec identify $file]
" } proc_footer } proc proc_header {} { puts {$Id: browse.cgi,v 1.6 2005/05/10 14:00:53 cinsk Exp $
} } set mode [::ncgi::value mode "thumbnails"] # # command line option parsing.. # proc help_and_exit {} { puts "usage: blah blah blah..." exit 0 } proc version_and_exit {} { puts "$argv0 version $version_string" exit 0 } proc query {msg answer_list args} { if {[llength $args] > 1} { error "wrong # of args: should be query answers ?default?" } } proc syserror {status msg} { global argv0 puts "$argv0: $msg" if {$status != 0} { if {$cgi_mode == 0} { exit $status } else { exit 0 } } } while {[llength $argv] != 0} { set first [lindex $argv 0] if {[string index $first 0] != "-"} { break } switch -glob -- $first { "-h" { help_and_exit } "--help" { help_and_exit } "-v" { version_and_exit } "--version" { version_and_exit } "--test" { set cgi_mode 1 } "--verbose" { set verbose_mode 1 } "*" { syserror 1 "unknown option \"$first\". try \"-h\" for more." } } set argv [lrange $argv 1 end] } # # Main. # if {$cgi_mode == 0} { proc_gen_thumbs exit 0 } puts "Content-type: text/html" puts "" if {[string compare $mode "thumbnails"] == 0} { proc_thumbnails } else { proc_slide } # # Local Variables: # coding: iso8859-1 # fill-column: 78 # End: #