home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
scripts
/
ckermit
/
photoalbum.~1~
< prev
next >
Wrap
Text File
|
2006-07-08
|
10KB
|
252 lines
#!/usr/local/test/bin/wermit +
#
# Usage: photoalbum.ksc [ keyword=value [ keyword=value [ ... ] ] ]
#
# Make web site of pictures.
# Assumes all pictures are jpg, in the current directory by themselves.
#
# Options (keywords):
# title="This will be the title"
# color=xxx (foreground text color, default black)
# background=yyy (background color, default white)
# language=zzz (english or spanish, default english)
# height=nnn (height for thumbnails in pixels, default 72)
# noscale=n (0 to scale photos, 1 not to scale, default 0)
#
# Makes an index page with thumbnails (or picture filenames if there are
# no thumbnails) and then a page for each picture with forward, back, and
# index links, with the ability to click on each picture to see the original.
# Page can be in Spanish or English.
#
# Overwrites any previous versions of the .html pages each time you run it.
#
# If ImageMagick is available, it is used to generate generate thumbnails
# for the index page. Otherwise the index page just contains a list of
# links to the individual HTML pages.
#
# Alternatively if you can make thumbnails some other way, they will be used
# if they are already there. For each file xxx.jpg, the corresponding
# thumbnail must be called xxx-t.jpg.
#
if llt \v(version) 800212 exit 1 C-Kermit 8.0.212 Dev.19 or later required.
if < \v(buildid) 20060707 exit 1 C-Kermit 8.0.212 Dev.19 or later required.
def USAGE {
echo
echo { Usage: photoalbum.ksc [ keyword=value [ keyword=value [ ... ] ] ]}
echo
echo { Makes a website in a directory containing .jpg images.}
echo { Index page shows thumbnails of the images.}
echo
echo { Options (keywords):}
echo { title="This will be the title"}
echo { color=xxx (foreground text color, default black)}
echo { background=yyy (background color, default white)}
echo { language=zzz (english or spanish, default english)}
echo { height=nnn (height for thumbnails in pixels, default 72)}
echo { noscale=n (0 to scale photos, 1 not to scale, default 0)}
echo { help (print this message)}
echo
exit 0
}
# Command-line processing - title and options
.height = 72 # Default thumbnail height
.noscale = 0 # Scale pictures to browser by default
.language = English # Default text language is English
.color = darkmagenta # Default text language is black
.background = beige # Default background color is white
for \%i 1 \v(argc)-1 1 { # Parse each option
void \fkeywordvalue(\&_[\%i]) # This function does it
if eq "\v(lastkwval)" "help" usage # If keyword was "help" give help
}
if not numeric \m(height) exit 1 Fatal - Height not numeric: \m(height)
if not numeric \m(noscale) exit 1 Fatal - Noscale not numeric: \m(noscale)
if match english \m(language)* .language = English
else if match spanish \m(language)* .language = Spanish
else exit 1 Fatal - Language "\m(language)" not supported
show macro title color background language height noscale
undef \%h \%w # Height and width clauses for HTML
if not \m(noscale) {
.\%h = { height="90%"} # Portrait
.\%w = { width="100%"} # Landscape
}
pwd
if eq \m(system) unix chmod 664 *.jpg
# Use Image Magick 'convert' (if available) to create thumbnails.
dir /array:&t /except:*-t.jpg *.jpg # Get list of non-thumbnail images
.need_thumbnails = 0 # Assume we don't need thumbnails
if def height .need_thumbnails = 1 # If height given maybe we do
if not \m(need_thumbnails) { # Or...
.\%t := \ffiles(*-t.jpg) # if we don't have a thumbnail for
if > \&t[0] \%t .need_thumbnails = 1 # every non-thumbnail
}
if \m(need_thumbnails) { # Need thumbnails.
!convert -version > /dev/null # Do we have Image Magick convert?
if fail {
echo Image Magick 'convert' not found - can't make thumbnails...
.need_thumbnails = 0
}
}
if \m(need_thumbnails) { # Need to and can make thumbnails...
echo Creating thumbails...
for i 1 \&t[0] 1 { # Go through non-thumbnail jpgs...
.t := \fstripx(\fbasename(\&t[i]),.)
.tt := \m(t)-t.jpg # Make name for thumbnail
if exist \m(tt) { # Already exists?
if \fpictureinfo(\m(tt),&d) { # get its height
if ( == \m(height) \&d[2] ) { # Same as requested height?
continue # Nothing to do
}
}
del /quiet \m(tt) # Delete existing thumbnail
}
xecho " \&t[i]" # Create new thumbnail
!convert \&t[i] -geometry 500x\m(height) \m(tt)
if fail echo PROBLEM WITH \&t[i] - Continuing...
chmod 644 \m(tt)
}
echo # Done with thumbnails
}
.\%t := \ffiles(*-t.jpg) # Now see how many thumbnails exist
# Localization (Spanish or English)...
.charset = iso-8859-1 # Character set is ISO 8859-1
undef langtag # No HMTL language tag yet
switch \m(language) { # Text messages for selected language
:spanish
.langtag = { lang="es"} # HTML language tag
if not def title .title = Fotos # Default title
.photo = Foto # Individual page title
.next = Adelante # Forward
.prev = Atrßs # Back
.index = Indice # Index
.up = Arriba
.msg1 = Haz clic en cualquier nombre para ver fotos # Legend for index
if \%t .msg1 = Haz clic en cualquier foto para entrar
.msg2 = (Haz clic para ver en tama±o original)
break
:english
.langtag = { lang="en"} # HTML language tag
if not def title .title = Photos # Default title
.photo = Photo # Individual page title
.next = Next # Forward
.prev = Prev # Back
.index = Index # Index
.up = Up
.msg1 = Click on any name to see photos # Legend for index
if \%t .msg1 = Click on any photo to enter
.msg2 = (Click to enlarge)
break
:default
stop 1 "No language!"
}
if \m(noscale) undef msg2
fopen /write \%o index.html # Create the index page
if fail stop 1 FOPEN index failed
# Write HTML prologue...
fwrite /line \%o <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
fwrite /line \%o <html\m(langtag)>
fwrite /line \%o <head>
fwrite /line \%o <title>\m(title)</title>
fwrite /line \%o -
<META http-equiv="Content-Type" content="text/html; charset=\m(charset)">
fwrite /line \%o </head>
fwrite /line \%o <body bgcolor="\m(background)" text="\m(color)">
fwrite /line \%o <h1>\m(title)</h1>
fwrite /line \%o "( <a href="..">\m(up)</a> ) "
fwrite /line \%o <i>(\m(msg1))</i><br>
dir /array:&a /except:*-t.jpg *.jpg # Get list of non-thumbnail JPGs
.\%n := \&a[0] # How many of these there are
for \%i 1 \%n 1 { # Loop through all non-thumbnails
xecho "FILENAME \&a[\%i] => " # Start to say what we're going
.\%b := \fstripx(\&a[\%i]) # Filename without ".jpg"
.\%f := \%b.html # Filename with ".html"
.orientation := \fpictureinfo(\&a[\%i]) # Get picture orientation
switch \m(orientation) {
:1, .\%p = "Landscape", break
:2, .\%p = "Portrait", break
:default, .\%p = "Unknown"
}
echo \%f (\%p) # Finish saying what we're doing
fopen /write \%c \%f # Create page for this picture
if fail exit 1 OPEN failed
fwrite /line \%c - # Write HTML prologue
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
fwrite /line \%c <html\m(langtag)>
fwrite /line \%c <head>
fwrite /line \%c <title>\m(photo) \#\%i - \m(title)</title>
fwrite /line \%c -
<META http-equiv="Content-Type" content="text/html; charset=\m(charset)">
fwrite /line \%c </head>
fwrite /line \%c <body bgcolor="\m(background)" text="\m(color)">
fwrite /line \%c <h2>\m(photo) \#\%i</h2>
fwrite /line \%c
if == \%i \%n { # If last picture there is no next.
fwrite /line \%c ( <a href="index.html">\m(index)</a> )
} else { # Not last picture
.\%x := \fstripx(\&a[\%i+1]).html # So make link to next.
fwrite /line \%c ( <a href="\%x">\m(next)</a> )
}
if != \%i 1 { # Not first picture?
.\%x := \fstripx(\&a[\%i-1]).html # Not first so link to previous
fwrite /line \%c " ( <a href="\%x">\m(prev)</a> ) "
}
if != \%i \%n { # Not last picture?
fwrite /line \%c ( <a href="index.html">\m(index)</a> ) # Link to index
}
if def msg2 fwrite /line \%c <small><i> \m(msg2)</i></small><br>
.\%x := \%b
.\%z = \fcontents(\%b)
if exist \%x.jpg .\%z = \fcontents(\%x)
switch \%p { # Make image fit in browser screen
:Portrait # Portrait
if \m(noscale) {
fwrite /line \%c <img src="\%b.jpg"\%h>
} else {
fwrite /line \%c <a href="\%z.jpg"><img src="\%b.jpg"\%h></a>
}
break
:Landscape # Landscape
if \m(noscale) {
fwrite /line \%c <img src="\%b.jpg"\%h>
} else {
fwrite /line \%c <a href="\%z.jpg"><img src="\%b.jpg"\%w></a>
}
break
:default
fwrite /line \%c <img src="\%b.jpg">
}
fwrite /line \%c <hr color="\m(color)"> # End of page
fwrite /line \%c </body>
fwrite /line \%c </html>
fclose \%c
if eq \m(system) unix chmod 664 \%f
.\%x := \fstripx(\%f)-t # Make entry in index page.
if exist \%x.jpg fwrite /line \%o {<a href="\%f"><img src="\%x.jpg"></a>}
else fwrite /line \%o [ <a href="\%f">\%f</a> ]
}
# Finish and close Index page
fwrite /line \%o <hr color="\m(color)"> # End of page
fwrite /line \%o </body>
fwrite /line \%o </html>
fclose \%o
if eq \m(system) unix chmod 664 index.html
exit