1     #!/usr/local/bin/perl
2     
3     use strict;
4     
5     my $TAG = "<! ADD HERE >";
6     use HTML::Entities;
7     use URI::Escape;
8     umask 0022;
9     
10    {
11      my @names = @ARGV ? @ARGV : grep { -f and -B } <*>;
12    
13      local @ARGV = "index.html";
14      local $^I = "~";
15    
16      while (<>) {
17 if (eof) {
18 print;                    # last line 
19          print "<! move the following table to the proper location >\n";
20          print "<table border=2> $TAG\n";
21          &scan_pictures(@names);
22          print "</table>\n";
23          last;
24        }
25        if (/\Q$TAG/o) {
26          print;                    # tag line
27          &scan_pictures(@names);
28          while (<>) {              # dump remaining lines
29            print;
30          }
31          last;
32        }
33        print;                      # default
34      }
35    }
36    exit 0;
37    
38    ## subroutines
39    
40    sub scan_pictures {
41      for (@_) {
42        next if /\.thumb\.jpg$/;
43        my $thumb = "$_.thumb.jpg";
44        next if -e $thumb;
45        my $pnm = &get_pnm($_) or next;
46        open PNMTOTHUMB,"| pnmscale -xy 100 100 | cjpeg -smoo 10 -qual 50 >$thumb"
47          or next;
48        print PNMTOTHUMB $pnm;
49        close PNMTOTHUMB;
50        print
51          "<tr><td><a href=\"",
52          encode_entities(uri_escape($_)),
53          "\"><img src=\"",
54          encode_entities(uri_escape($thumb)),
55          "\" alt=\"[thumbnail of ",
56          encode_entities($_),
57          "]\"></a></td><td>",
58          int((1023 + -s)/1024),
59          "K</td><td>\n  Description not provided\n</td>",
60          "</tr>\n";
61      }
62    }
63    
64    sub get_pnm {
65      local $_ = shift;
66      for my $cmd ("djpeg $_", "giftopnm $_") {
67        my $pnm = `$cmd 2>/dev/null`;
68        return $pnm unless $?;
69      }
70      return;
71    }