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=grep (/\.(jpe?g|png|tiff?|gif)$/i, <*>) ;
68 my @movielist= grep(/\.(mp4|avi|flv|mpg)$/i,<*>);
69 print STDERR "Pictures found @piclist\n";
70 print STDERR "Videos found @movielist\n";
72 for ($j=0;$j<=$#piclist;$j++) {
74 $prev = $piclist[$j-1] if $j>0;
76 $next = $piclist[$j+1];
82 my $info = image_info($_);
83 my $thumbname=rescale($_,THUMBDIR,THUMBSIZE,$info);
84 my $inlinename=rescale($_,INLINEDIR,INLINESIZE,$info);
85 my $comment = make_comment_html($info);
86 my ($w,$h) = dim(image_info(THUMBDIR."/$_"));
87 print OUT "<tr>\n" if ($i % COLUMNS == 0);
88 print OUT "<td valign=top align=center><a href=\"$_.html\"",($opt_n?"
89 target=\"_blank\"":""),"><img border=0 width=$w height=$h src=\"$thumbname\"></a><br>$comment</td>\n";
90 print OUT "</tr>\n" if (++$i % COLUMNS == 0);
91 print STDERR " html...";
92 make_html($_,$info,$comment,$inlinename);
93 print STDERR "\b\b\b done";
97 print OUT "</tr>\n" unless ($i % COLUMNS == 0);
98 print OUT "</table></body></html>\n";
102 my ($name,$out_dir,$maxsize,$info) = @_;
103 my ($w,$h) = dim($info);
104 if ($w<$maxsize && $h<$maxsize) {
105 #picture is small enough to be used without rescaling
108 my $result = "$out_dir/$name";
109 if ( ! -f $result || -M $name < -M $result) {
110 print STDERR " $out_dir...";
112 system "convert", "-geometry", $maxsize."x".$maxsize,$_,$result;
113 print STDERR "\b\b\b ";
118 sub make_comment_html {
122 ref($info->{"Comment"})?join("\n",@{$info->{"Comment"}}):$info->{"Comment"};
123 $comment =~s/\&/&/;
124 $comment =~s/"/"/;
125 $comment =~s/>/>/;
126 $comment =~s/</</;
135 open HTML, ">$imgfile.html";
136 my ($w,$h) = dim($info);
137 my ($w1,$h1) = dim(image_info(INLINEDIR."/".$imgfile));
138 print HTML "<html><head><title>$dir:$imgfile</title></head><body>
139 <h2>$dir</h2>",($opt_f?"":"<h1>$imgfile</h1>"),(defined($info->{'DateTime'})?"<p
140 class=\"timestamp\">Time: $info->{'DateTime'}</p>":""),"<p>$comment</p>",
141 "<img src=\"".$inline."\" width=$w1 height=$h1>",
145 <table width=100%><tr><td align=left>
146 ",($prev?"<a href=\"$prev.html\"><<</a>":" "),
147 "</td><td align=center><a href=\".\">Up</A></td><td align=right>\n",
148 ,($next?"<a href=\"$next.html\">>></a>":" "),
149 "</td></tr></table>\n",
150 ($opt_l?"":"<a href=\"$imgfile\">$imgfile ($w x $h)</a>"),"
158 unlink "$imgfile.html";