2 use constant THUMBSIZE => 150;
3 use constant COLUMNS=>5;
4 use constant THUMBDIR=>".thumbs";
5 use constant INLINESIZE=> 600;
6 use constant INLINEDIR=>".inline";
7 use Image::Info qw(image_info dim);
13 imagedir - generates HTML index for directory of pictures.
17 imagedir [-f] [B<-n>] [B<-l>] [B<-t> I<title>]
21 Generates two hidden subdirs under current directory - B<.thumbs> and
22 B<.inlines> with smaller copies of the images and generates
23 B<index.html> with small (fit in the square 150x150) copies of the
26 Each image is a link to generated HTML page with bigger (fit into
27 600x600) copy of the image and (unless supressed) link to full sized
28 image. If image contain JPEG or GIF comment, comment is inserted into
37 Don't use filenames as headers of individual picture page
41 Supress link to fullsized images
45 If specified, all links in B<index.html> would have target="_blank"
50 Title. If none given, directory name is used.
56 use vars qw($opt_t $opt_n $opt_l $opt_f);
59 my $dir = $opt_t || (split ("/",cwd()))[-1];
60 mkdir THUMBDIR if (! -d THUMBDIR);
61 mkdir INLINEDIR if (! -d INLINEDIR);
63 open OUT,">index.html";
64 print OUT "<HTML><HEAD><TITLE>$dir</TITLE>\n<BODY>\n<H1>$dir</H1>\n"
65 ."<p align=\"center\"><A HREF=\"..\">back</A></p>".
66 "<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=0>\n";
67 my @piclist=(<*.jpg>,<*.gif>,<*.png>) ;
68 print STDERR "@piclist\n";
70 for ($j=0;$j<=$#piclist;$j++) {
72 $prev = $piclist[$j-1] if $j>0;
74 $next = $piclist[$j+1];
79 my $info = image_info($_);
80 my $thumbname=rescale($_,THUMBDIR,THUMBSIZE,$info);
81 my $inlinename=rescale($_,INLINEDIR,INLINESIZE,$info);
82 my $comment = make_comment_html($info);
83 my ($w,$h) = dim(image_info(THUMBDIR."/$_"));
84 print OUT "<tr>\n" if ($i % COLUMNS == 0);
85 print OUT "<td valign=top align=center><a href=\"$_.html\"",($opt_n?"
86 target=\"_blank\"":""),"><img border=0 width=$w height=$h src=\"$thumbname\"></a><br>$comment</td>\n";
87 print OUT "</tr>\n" if (++$i % COLUMNS == 0);
88 print STDERR " html...";
89 make_html($_,$info,$comment,$inlinename);
90 print STDERR "\b\b\b done";
94 print OUT "</tr>\n" unless ($i % COLUMNS == 0);
95 print OUT "</table></body></html>\n";
99 my ($name,$out_dir,$maxsize,$info) = @_;
100 my ($w,$h) = dim($info);
101 if ($w<$maxsize && $h<$maxsize) {
102 #picture is small enough to be used without rescaling
105 my $result = "$out_dir/$name";
106 if ( ! -f $result || -M $name < -M $result) {
107 print STDERR " $out_dir...";
109 system "convert", "-geometry", $maxsize."x".$maxsize,$_,$result;
110 print STDERR "\b\b\b ";
115 sub make_comment_html {
119 ref($info->{"Comment"})?join("\n",@{$info->{"Comment"}}):$info->{"Comment"};
120 $comment =~s/\&/&/;
121 $comment =~s/"/"/;
122 $comment =~s/>/>/;
123 $comment =~s/</</;
132 open HTML, ">$imgfile.html";
133 my ($w,$h) = dim($info);
134 my ($w1,$h1) = dim(image_info(INLINEDIR."/".$imgfile));
135 print HTML "<html><head><title>$dir:$imgfile</title></head><body>
136 <h2>$dir</h2>",($opt_f?"":"<h1>$imgfile</h1>"),(defined($info->{'DateTime'})?"<p
137 class=\"timestamp\">Time: $info->{'DateTime'}</p>":""),"<p>$comment</p>",
138 "<img src=\"".$inline."\" width=$w1 height=$h1>",
142 <table width=100%><tr><td align=left>
143 ",($prev?"<a href=\"$prev.html\"><<</a>":" "),
144 "</td><td align=center><a href=\".\">Up</A></td><td align=right>\n",
145 ,($next?"<a href=\"$next.html\">>></a>":" "),
146 "</td></tr></table>\n",
147 ($opt_l?"":"<a href=\"$imgfile\">$imgfile ($w x $h)</a>"),"
155 unlink "$imgfile.html";