5 use open OUT => ":locale";
6 use constant THUMBSIZE => 150;
7 use constant COLUMNS=>5;
8 use constant THUMBDIR=>".thumbs";
9 use constant INLINESIZE=> 600;
10 use constant INLINEDIR=>".inline";
11 use Image::Info qw(image_info dim);
17 imagedir - generates HTML index for directory of pictures.
21 imagedir [-f] [B<-n>] [B<-l>] [B<-t> I<title>]
25 Generates two hidden subdirs under current directory - B<.thumbs> and
26 B<.inlines> with smaller copies of the images and generates
27 B<index.html> with small (fit in the square 150x150) copies of the
30 Each image is a link to generated HTML page with bigger (fit into
31 600x600) copy of the image and (unless supressed) link to full sized
32 image. If image contain JPEG or GIF comment, comment is inserted into
41 Don't use filenames as headers of individual picture page
45 Supress link to fullsized images
49 If specified, all links in B<index.html> would have target="_blank"
54 Title. If none given, directory name is used.
60 use vars qw($opt_t $opt_n $opt_l $opt_f);
63 my $dir = $opt_t || (split ("/",cwd()))[-1];
64 mkdir THUMBDIR if (! -d THUMBDIR);
65 mkdir INLINEDIR if (! -d INLINEDIR);
67 open OUT,">","index.html";
68 print OUT "<HTML><HEAD><TITLE>$dir</TITLE>\n<BODY>\n<H1>$dir</H1>\n"
69 ."<p align=\"center\"><A HREF=\"..\">back</A></p>".
70 "<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=0>\n";
71 my @piclist=grep (/\.(jpe?g|png|tiff?|gif)$/i, <*>) ;
72 my @movielist= grep(/\.(mp4|avi|flv|mpg)$/i,<*>);
73 print STDERR "Pictures found @piclist\n";
74 print STDERR "Videos found @movielist\n";
76 for ($j=0;$j<=$#piclist;$j++) {
78 $prev = $piclist[$j-1] if $j>0;
80 $next = $piclist[$j+1];
86 my $info = image_info($_);
87 my $thumbname=rescale($_,THUMBDIR,THUMBSIZE,$info);
88 my $inlinename=rescale($_,INLINEDIR,INLINESIZE,$info);
89 my $comment = make_comment_html($info);
90 my ($w,$h) = dim(image_info(THUMBDIR."/$_"));
91 print OUT "<tr>\n" if ($i % COLUMNS == 0);
92 print OUT "<td valign=top align=center><a href=\"$_.html\"",($opt_n?"
93 target=\"_blank\"":""),"><img border=0 width=$w height=$h src=\"$thumbname\"></a><br>$comment</td>\n";
94 print OUT "</tr>\n" if (++$i % COLUMNS == 0);
95 print STDERR " html...";
96 make_html($_,$info,$comment,$inlinename);
97 print STDERR "\b\b\b done";
101 print OUT "</tr>\n" unless ($i % COLUMNS == 0);
102 print OUT "</table></body></html>\n";
106 my ($name,$out_dir,$maxsize,$info) = @_;
107 my ($w,$h) = dim($info);
108 if ($w<$maxsize && $h<$maxsize) {
109 #picture is small enough to be used without rescaling
112 my $result = "$out_dir/$name";
113 if ( ! -f $result || -M $name < -M $result) {
114 print STDERR " $out_dir...";
116 system "convert", "-geometry", $maxsize."x".$maxsize,$_,$result;
117 print STDERR "\b\b\b ";
122 sub make_comment_html {
124 my $comment = Encode::decode("koi8-r",ref($info->{"Comment"})?join("\n",@{$info->{"Comment"}}):$info->{"Comment"});
125 $comment =~s/\&/&/;
126 $comment =~s/"/"/;
127 $comment =~s/>/>/;
128 $comment =~s/</</;
137 open HTML, ">", "$imgfile.html";
138 my ($w,$h) = dim($info);
139 my ($w1,$h1) = dim(image_info(INLINEDIR."/".$imgfile));
140 print HTML "<html><head><title>$dir:$imgfile</title></head><body>
141 <h2>$dir</h2>",($opt_f?"":"<h1>$imgfile</h1>"),(defined($info->{'DateTime'})?"<p
142 class=\"timestamp\">Time: $info->{'DateTime'}</p>":""),"<p>$comment</p>",
143 "<img src=\"".$inline."\" width=$w1 height=$h1>",
147 <table width=100%><tr><td align=left>
148 ",($prev?"<a href=\"$prev.html\"><<</a>":" "),
149 "</td><td align=center><a href=\".\">Up</A></td><td align=right>\n",
150 ,($next?"<a href=\"$next.html\">>></a>":" "),
151 "</td></tr></table>\n",
152 ($opt_l?"":"<a href=\"$imgfile\">$imgfile ($w x $h)</a>"),"
160 unlink "$imgfile.html";