-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkindex.pl
executable file
·76 lines (55 loc) · 1.47 KB
/
mkindex.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
my $USAGE = <<END;
mkindex.pl
Given a list of JPEG files in the current directory, make a simple photo
album. Output goes to ./index.html.
Usage: mkindex.pl <title> <file1> <file2> ... <filen>
Where:
<title> is the page title
<file1> ... <filen> are the JPEG files.
END
use strict;
use warnings;
my ($title, @files) = @ARGV;
die $USAGE unless defined $title;
# Create thumbnails.
my @thumbs;
foreach my $filename (@files) {
# Make extensions lowercase while we're at it.
if ($filename =~ /(.*)\.(JPG)/) {
my $new_filename = "$1.jpg";
system "mv $filename $new_filename\n";
$filename = $new_filename;
}
if ($filename =~ /(.*)\.(jpg)/) {
my $prefix = $1;
my $suffix = $2;
my $thumbname = "${prefix}_small.${suffix}";
print "Converting $filename...\n";
system "convert -resize 20% $filename $thumbname";
push @thumbs, $thumbname;
} else {
die "error processing filename $filename";
}
}
# Generate the HTML
my @lines;
for (my $i = 0; $i < (scalar @files); $i++) {
my $file = $files[$i];
my $thumb = $thumbs[$i];
my $line = "<p><a href=$file><img src=$thumb></a>";
push @lines, $line;
}
my $lines = join "\n", @lines;
my $output = <<END;
<html>
<head><title>$title</title></head>
<body>
<h1>$title</h1>
$lines
</body>
</html>
END
open OUT, ">index.html" or die "Couldn't open index.html for writing.";
print OUT $output;
close OUT;