# Usefull stuff for picture archives. # # # <: %picturedefault = ( 'dir' => 'pictures', # Directory containing pictures 'basename' => 'picture', # Base name of pictures (foo-01.jpg etc.) 'fname' => 'picture', # Base name of HTML file for a picture 'suffix' => 'html', # Suffix for the HTML file 'append' => '', # not yet fully supported (I guess...) 'append-thumb' => '-thumb', # Appendix for thumbnails 'append-large' => '-large', # Appendix for large images 'digits' => 3, # Number of digits in filename 'captionlength' => 50, # Number of characters to copy from %caption ); # Apply defaults if no settings were made # foreach $k (keys %picturedefault) { $picture{$k} = $picturedefault{$k} if (! exists $picture{$k}); } :> # Creates a nice overview page for all pictures # > > <: $picture{'cols'} = ; $picture{'min'} = ""; $picture{'max'} = ""; if (opendir(DIR, "$picture{'dir'}")) { @all = sort (readdir (DIR)); closedir(DIR); foreach $f (@all) { next until ($f =~ /^$picture{'basename'}-(\d+)$picture{'append'}\.jpg$/); next if ( ($picture{'min'} && $1 < $picture{'min'}) || ($picture{'max'} && $1 > $picture{'max'}) ); push (@files, $f); } } $rows = ($#files+1)/$picture{'cols'}; $pat = "%" . "0" . sprintf ("%d", $picture{'digits'}) . "d"; $row = 0; while ($row < $rows) { print ""; $col = 0; while ($col < $picture{'cols'}) { $nr = $row*$picture{'cols'}+$col; if ($nr <= $#files) { $fname = $files[$nr]; $pivot = $fname; $pivot =~ s/\.jpg$//; $pivot =~ s/^$picture{'basename'}$picture{'append'}-//; $pivot = sprintf ("%d", $pivot); $fname = sprintf ("%s-$pat%s.jpg", $picture{'basename'}, $pivot, $picture{'append-thumb'}); $alt = $caption{$pivot}; $alt =~ s/\r?\n.*//; if (length ($alt) > $picture{'captionlength'}) { $alt = substr ($alt, 0, $picture{'captionlength'}) . "..."; } $alt = sprintf ("Picture %d", $pivot) if (!length ($alt)); print ""; } $col++; } print ""; $row++; } :>
"; printf "\"%s\"", $picture{'fname'}, $pivot, $picture{'suffix'}, $picture{'dir'}, $fname, $alt; print "
# Creates one picture #

<: $id = ""; $pat = "%" . "0" . sprintf ("%d", $picture{'digits'}) . "d"; if (!length ($id)) { $id = $WML_SRC_FILENAME; $id =~ s/\.wml$//; $id =~ s/^$picture{'fname'}-//; $id = sprintf ("%d", $id); } $fname = sprintf ("%s-$pat%s.jpg", $picture{'basename'}, $id, $picture{'append'}); $largefile = sprintf ("%s/%s-$pat%s.jpg", $picture{'dir'}, $picture{'basename'}, $id, $picture{'append-large'}); if ( -r $largefile) { printf "\"Picture", $largefile, $picture{'dir'}, $fname, $id; } else { printf "\"Picture", $picture{'dir'}, $fname, $id; } $alt = $caption{$id}; printf "
%s", $alt if (length ($alt)); if (opendir(DIR, "$picture{'dir'}")) { @files = sort (grep (/^$picture{'basename'}$picture{'append'}-\d+.jpg$/,readdir(DIR))); closedir(DIR); } for ($pivot = -1; ($pivot <= $#files) && ($files[$pivot] ne $fname); $pivot++) {}; print "

" if ($pivot > 0 || $pivot <= $#files); if ($pivot > 0) { $id = $files[$pivot-1]; $id =~ s/\.jpg//; $id =~ s/^$picture{'basename'}$picture{'append'}-//; $id = sprintf ("%d", $id); printf "previous ", $picture{'fname'}, $id, $picture{'suffix'}; } if ($pivot <= $#files) { $id = $files[$pivot+1]; $id =~ s/\.jpg//; $id =~ s/^$picture{'basename'}$picture{'append'}-//; $id = sprintf ("%d", $id); printf " next", $picture{'fname'}, $id, $picture{'suffix'}; } :>

# Inlines one picture # "right" "" > "left" "" >
%body  > <: $id = ""; $pat = "%" . "0" . sprintf ("%d", $picture{'digits'}) . "d"; $fname = sprintf ("%s-$pat%s.jpg", $picture{'basename'}, $id, $picture{'append-thumb'}); $alt = $caption{$id}; printf "\"%s\"", $picture{'fname'}, $id, $picture{'suffix'}, $picture{'dir'}, $fname, $alt; :>   %body
# Local variables: # mode: indented-text # mode: auto-fill # end: