bigsh: Get rid of warning about missing font, delete `-fb` from xterm
[sunny256-utils.git] / create_imgindex
blob2ae15b3d3d588060eefca668bfb004a20828217c
1 #!/usr/bin/env perl
3 #=======================================================================
4 # create_imgindex
5 # File ID: e315d656-1cb0-11de-a0da-000475e441b9
6 # Create HTML page with collection of images
8 # Character set: UTF-8
9 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'generate' => 0,
26 'help' => 0,
27 'language' => "en",
28 'output-file' => "",
29 'title' => "",
30 'verbose' => 0,
31 'version' => 0,
35 our $progname = $0;
36 $progname =~ s/^.*\/(.*?)$/$1/;
37 our $VERSION = "0.00";
39 my $Author = txt_to_xml('Øyvind A. Holm <sunny@sunbase.org>'); # FIXME: Hardcoding
40 my $cmdline_str = txt_to_xml(join(" ", @ARGV));
42 Getopt::Long::Configure("bundling");
43 GetOptions(
45 "debug" => \$Opt{'debug'},
46 "generate|g" => \$Opt{'generate'},
47 "help|h" => \$Opt{'help'},
48 "language|l=s" => \$Opt{'language'},
49 "output-file|o=s" => \$Opt{'output-file'},
50 "title|t=s" => \$Opt{'title'},
51 "verbose|v+" => \$Opt{'verbose'},
52 "version" => \$Opt{'version'},
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'debug'} && ($Debug = 1);
57 $Opt{'help'} && usage(0);
58 if ($Opt{'version'}) {
59 print_version();
60 exit(0);
63 my $Title = txt_to_xml($Opt{'title'}) || die("$progname: -t/--title not specified\n");;
64 my $Outfile = txt_to_xml($Opt{'output-file'}) || die("$progname: -o/--output-file not specified\n");;
65 scalar(@ARGV) || die("$progname: No filenames specified\n");
67 my $is_svn_wc = -d ".svn/." ? 1 : 0;
69 for my $Dir (qw{4288x2848 2144x1424 1072x712 536x356 thumbs}) {
70 if (!-d "$Dir/.") {
71 mkdir($Dir) || die("$progname: $Dir: mkdir() error: $!\n");
72 $is_svn_wc && mysyst("svn", "add", $Dir);
74 if (!-e "$Dir/.htaccess") {
75 open(OutFP, ">$Dir/.htaccess") || die("$progname: $Dir/.htaccess: Cannot create file: $!\n");
76 chomp(my $file_id = `fileid -t htaccess $Dir/.htaccess`);
77 print(OutFP <<END);
78 $file_id
80 DirectoryIndex SpesialIndex.html
81 Options Indexes
82 IndexOptions FancyIndexing NameWidth=* DescriptionWidth=*
83 AddType text/plain;charset=UTF-8 txt
84 AddType text/html;charset=UTF-8 html
85 AddDefaultCharset UTF-8
86 END
87 close(OutFP);
88 if ($is_svn_wc) {
89 mysyst("svn", "add", "$Dir/.htaccess");
90 mysyst("keyw", "$Dir/.htaccess");
95 my @time_array = localtime(time);
96 my $Year = $time_array[5] + 1900;
98 my $files_str = "";
99 my %smsum = ();
100 my @files_found = ();
102 open(OutFP, ">", $Outfile) || die("$progname: $Outfile: Cannot create file: $!\n");
104 for my $t (@ARGV) {
105 if (-r $t) {
106 msg(0, "$t");
107 chomp($smsum{$t} = `smsum <$t`);
108 $files_str .= sprintf("<file> <name>%s</name> <smsum>%s</smsum> </file> ", txt_to_xml($t), $smsum{$t});
109 if ($Opt{'generate'}) {
110 mysyst("cp -Lp $t 4288x2848/$t");
111 mysyst("convert -resize 2144 4288x2848/$t 2144x1424/$t");
112 mysyst("convert -resize 1072 2144x1424/$t 1072x712/$t");
113 mysyst("convert -resize 536 1072x712/$t 536x356/$t");
114 mysyst("convert -resize 160 536x356/$t thumbs/$t");
116 push(@files_found, $t);
117 } else {
118 warn("$progname: $t: Cannot open file for read: $!\n");
122 chomp(my $uuid = `suuid -t create_imgindex --raw -c "<c_create_imgindex> <cmdline>$cmdline_str</cmdline> <filename>$Outfile</filename> $files_str</c_create_imgindex>"`)
123 || die("$progname: suuid error");
125 my $ignorefile = ".$uuid.ignore.tmp";
126 if ($is_svn_wc) {
127 if (open(TmpFP, ">", $ignorefile)) {
128 printf(TmpFP "%s\n", join("\n", @files_found));
129 close(TmpFP);
132 if ($Opt{'generate'}) {
133 for my $dir (qw{4288x2848 2144x1424 1072x712 536x356 thumbs}) {
134 if (chdir($dir)) {
135 mysyst("mkFiles");
136 if ($is_svn_wc) {
137 mysyst("svn add Files.smsum");
139 chdir("..");
140 } else {
141 warn("$progname: $dir: Cannot chdir(), mkFiles not executed: $!\n");
143 $is_svn_wc && mysyst("svn -F $ignorefile ps svn:ignore $dir");
146 $is_svn_wc && unlink($ignorefile);
148 print(OutFP <<END);
149 <?xml version="1.0" encoding="UTF-8"?>
150 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
151 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="$Opt{'language'}" lang="$Opt{'language'}">
152 <!-- File ID: $uuid -->
153 <head>
154 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
155 <title>$Title</title>
156 <style type="text/css">
157 <!--
158 body { background-color: white; color: black; font-family: sans-serif; }
159 a:link { color: blue; background-color: white; }
160 a:visited { color: maroon; background-color: white; }
161 a:active { color: fuchsia; background-color: white; }
162 h1 { text-align: center; font-size: 200%; font-weight: bold; }
163 h2 { text-align: center; font-size: 120%; font-weight: bold; }
164 table.main { margin: 0 auto; }
165 td.head { text-align: center; vertical-align: middle; }
166 td.dirtxt { text-align: left; vertical-align: middle; }
167 td.dirs { text-align: center; vertical-align: middle; width: 25%; }
168 td.image { text-align: center; vertical-align: middle; }
169 td.text { text-align: center; vertical-align: top; font-size: 80%; }
170 td.lefticon { text-align: center; vertical-align: middle; font-size: 80%; }
171 td.righticon { text-align: center; vertical-align: middle; font-size: 80%; }
172 td.footer { text-align: center; vertical-align: top; width: 100%; font-size: 100%; }
174 </style>
175 <meta name="author" content="Øyvind A. Holm — sunny\@sunbase.org" />
176 <meta name="copyright" content="©$Year- Øyvind A. Holm" />
177 <link rev="made" href="mailto:sunny\@sunbase.org" />
178 </head>
179 <body>
180 <table class="main" cellpadding="10" cellspacing="0" border="1">
181 <tr>
182 <td class="head" colspan="4">
183 <h1>$Title</h1>
184 <table width="100%">
185 <tr>
186 <td colspan="4" class="dirtxt">
187 <h2>Directories:</h2>
188 </td>
189 </tr>
190 <tr>
191 <td class="dirs">
192 <a href="4288x2848/">4288x2848/</a>
193 </td>
194 <td class="dirs">
195 <a href="2144x1424/">2144x1424/</a>
196 </td>
197 <td class="dirs">
198 <a href="1072x712/">1072x712/</a>
199 </td>
200 <td class="dirs">
201 <a href="536x356/">536x356/</a>
202 </td>
203 </tr>
204 </table>
205 </td>
206 </tr>
209 my ($Count, $create_td) = (0, 0);
211 for my $Curr (@ARGV) {
212 if (!$Count) {
213 print(OutFP " <tr>\n");
215 print(OutFP <<END);
216 <td>
217 <!-- $smsum{$Curr} -->
218 <table width="100%" cellpadding="2" cellspacing="0" border="0">
219 <tr>
220 <td class="image" colspan="2">
221 <img src="thumbs/$Curr" width="160" alt="$Curr" />
222 </td>
223 </tr>
224 <tr>
225 <td class="text">
226 [<a href="4288x2848/$Curr">4288x2848</a>]<br />
227 [<a href="1072x712/$Curr">1072x712</a>]
228 </td>
229 <td class="text">
230 [<a href="2144x1424/$Curr">2144x1424</a>]<br />
231 [<a href="536x356/$Curr">536x356</a>]
232 </td>
233 </tr>
234 <tr>
235 <td class="text" colspan="2">
236 <b>$Curr</b>
237 </td>
238 </tr>
239 </table>
240 </td>
242 $Count++;
243 if ($Count > 3) {
244 print(OutFP " </tr>\n");
245 $Count = 0;
246 $create_td = 1;
250 if ($Count) {
251 $create_td && printf(OutFP " <td colspan=\"%u\">\n </td>\n", 4-$Count);
252 print(OutFP " </tr>\n");
255 print(OutFP <<END);
256 <tr>
257 <td colspan="4">
258 <table cellpadding="5" cellspacing="0" border="0">
259 <tr>
260 <td class="lefticon">
261 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10.png" alt="Valid XHTML 1.0" width="88" height="31" style="border: 0;" /></a>
262 </td>
263 <td class="footer" colspan="2">
264 ©opyleft $Year- Øyvind A. Holm &lt;sunny\@sunbase.org&gt;<br />
265 License:
266 <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported</a>
267 </td>
268 <td class="righticon">
269 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="http://www.w3.org/Icons/valid-css.png" alt="Valid CSS" width="88" height="31" style="border: 0;" /></a>
270 </td>
271 </tr>
272 </table>
273 </td>
274 </tr>
275 </table>
276 </body>
277 </html>
280 close(OutFP);
282 sub mysyst {
283 # {{{
284 my @Args = @_;
285 my $system_txt = sprintf("system(\"%s\");", join("\", \"", @Args));
286 msg(1, "Executing '$system_txt'...");
287 system(@_);
288 # }}}
289 } # mysyst()
291 sub txt_to_xml {
292 # {{{
293 my $Txt = shift;
294 $Txt =~ s/&/&amp;/gs;
295 $Txt =~ s/</&lt;/gs;
296 $Txt =~ s/>/&gt;/gs;
297 return($Txt);
298 # }}}
299 } # txt_to_xml()
301 sub print_version {
302 # Print program version {{{
303 print("$progname v$VERSION\n");
304 # }}}
305 } # print_version()
307 sub usage {
308 # Send the help message to stdout {{{
309 my $Retval = shift;
311 if ($Opt{'verbose'}) {
312 print("\n");
313 print_version();
315 print(<<END);
317 Usage: $progname [options] -o OUTFILE -t TITLE [images ...]
319 Options:
321 -g, --generate
322 Generate resized images in subdirectory tree. Needs convert(1) from
323 the ImageMagick package.
324 -h, --help
325 Show this help.
326 -l X, --language X
327 Use language code X. Default: "en".
328 -o X, --output-file X
329 Store output in file X.
330 -t X, --title X
331 Use title and header X.
332 -v, --verbose
333 Increase level of verbosity. Can be repeated.
334 --version
335 Print version information.
336 --debug
337 Print debugging messages.
340 exit($Retval);
341 # }}}
342 } # usage()
344 sub msg {
345 # Print a status message to stderr based on verbosity level {{{
346 my ($verbose_level, $Txt) = @_;
348 if ($Opt{'verbose'} >= $verbose_level) {
349 print(STDERR "$progname: $Txt\n");
351 # }}}
352 } # msg()
354 sub D {
355 # Print a debugging message {{{
356 $Debug || return;
357 my @call_info = caller;
358 chomp(my $Txt = shift);
359 my $File = $call_info[1];
360 $File =~ s#\\#/#g;
361 $File =~ s#^.*/(.*?)$#$1#;
362 print(STDERR "$File:$call_info[2] $$ $Txt\n");
363 return("");
364 # }}}
365 } # D()
367 __END__
369 # Plain Old Documentation (POD) {{{
371 =pod
373 =head1 NAME
377 =head1 SYNOPSIS
379 [options] [file [files [...]]]
381 =head1 DESCRIPTION
385 =head1 OPTIONS
387 =over 4
389 =item B<-h>, B<--help>
391 Print a brief help summary.
393 =item B<-v>, B<--verbose>
395 Increase level of verbosity. Can be repeated.
397 =item B<--version>
399 Print version information.
401 =item B<--debug>
403 Print debugging messages.
405 =back
407 =head1 BUGS
411 =head1 AUTHOR
413 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
415 =head1 COPYRIGHT
417 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
418 This is free software; see the file F<COPYING> for legalese stuff.
420 =head1 LICENCE
422 This program is free software: you can redistribute it and/or modify it
423 under the terms of the GNU General Public License as published by the
424 Free Software Foundation, either version 2 of the License, or (at your
425 option) any later version.
427 This program is distributed in the hope that it will be useful, but
428 WITHOUT ANY WARRANTY; without even the implied warranty of
429 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
430 See the GNU General Public License for more details.
432 You should have received a copy of the GNU General Public License along
433 with this program.
434 If not, see L<http://www.gnu.org/licenses/>.
436 =head1 SEE ALSO
438 =cut
440 # }}}
442 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :