Added a couple of useful <tags> for processing pictures
authorJoey Schulze <joey@infodrom.org>
Mon, 3 Dec 2001 00:46:37 +0000 (00:46 +0000)
committerJoey Schulze <joey@infodrom.org>
Mon, 3 Dec 2001 00:46:37 +0000 (00:46 +0000)
Styles/pictures.style [new file with mode: 0644]

diff --git a/Styles/pictures.style b/Styles/pictures.style
new file mode 100644 (file)
index 0000000..be01613
--- /dev/null
@@ -0,0 +1,187 @@
+# Usefull stuff for picture archives.
+
+# <overview [cols=3]>
+# <picture [id=$filenameid]>
+# <picture-table id=nnn>
+
+<:
+
+  %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
+                    '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
+#
+<define-tag overview>
+<preserve cols>
+<set-var %attributes>
+
+<if <not <get-var cols>>
+  <set-var cols=3>
+>
+
+<table width=100% border=0 cellpadding=0 cellspacing=2>
+
+<:
+    $picture{'cols'} = <get-var cols>;
+
+    if (opendir(DIR, "$picture{'dir'}")) {
+       @files = sort (grep (/^$picture{'basename'}$picture{'append'}-\d+.jpg$/,readdir(DIR)));
+       closedir(DIR);
+    }
+    $rows = ($#files+1)/$picture{'cols'};
+
+    $pat = "%" . "0" . sprintf ("%d", $picture{'digits'}) . "d";
+    $row = 0;
+    while ($row < $rows) {
+       print "<tr>";
+
+       $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 "<td align=\"center\"><font face=\"Helvetica,Arial\">";
+               printf "<a href=\"%s-$pat.%s\"><img src=\"%s/%s\" border=\"0\" alt=\"%s\"></a>",
+                   $picture{'fname'}, $pivot, $picture{'suffix'}, $picture{'dir'}, $fname, $alt;
+               print "</font></td>";
+           }
+           $col++;
+       }
+       print "</tr>";
+       $row++;
+    }
+:>
+
+</table>
+
+<restore cols>
+</define-tag>
+
+
+# Creates one picture
+#
+<define-tag picture whitespace=delete>
+<preserve id>
+<set-var %attributes>
+
+<p><center>
+
+<:
+  $id = "<get-var 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'});
+  printf "<img src=\"%s/%s\" alt=\"Picture %d\">", $picture{'dir'}, $fname, $id;
+
+  $alt = $caption{$id};
+  printf "<br>%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 "<p>" 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 "<a href=\"%s-$pat.%s\">previous</a>&nbsp;", $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 "&nbsp;<a href=\"%s-$pat.%s\">next</a>", $picture{'fname'}, $id, $picture{'suffix'};
+  }
+
+:>
+
+</center>
+
+<restore id>
+</define-tag>
+
+# Inlines one picture
+#
+<define-tag picture-table endtag=required>
+<preserve id placement>
+<set-var %attributes>
+
+<table width=100% cellpadding=0 cellspacing=0 border=0>
+<tr>
+
+<ifeq <get-var placement> "right"
+  "<td valign=top align=left><font face="Helvetica,Arial">%body</font></td>
+   <td>&nbsp;</td>"
+>
+
+<td valign=top align=<get-var placement>><font face="Helvetica,Arial">
+<:
+  $id = "<get-var id>";
+  $pat = "%" . "0" . sprintf ("%d", $picture{'digits'}) . "d";
+
+  $fname = sprintf ("%s-$pat%s.jpg", $picture{'basename'}, $id, $picture{'append-thumb'});
+  $alt = $caption{$id};
+
+  printf "<a href=\"%s-$pat.%s\"><img src=\"%s/%s\" border=\"0\" alt=\"%s\"></a>",
+      $picture{'fname'}, $id, $picture{'suffix'}, $picture{'dir'}, $fname, $alt;
+:>
+</font></td>
+
+<ifeq <get-var placement> "left"
+  "<td>&nbsp;</td>
+   <td valign=top align=left><font face="Helvetica,Arial">%body</font></td>"
+>
+
+</table>
+
+<restore id placement>
+</define-tag>
+