-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_lightbox.pl
executable file
·124 lines (106 loc) · 3.2 KB
/
make_lightbox.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl -w
use warnings;
use strict;
# created 11/22/00 for makeing web pages out of directories of pictures
# (C) 1999 by Brian Manning <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
my @filedir= <*.jpg>;
my $start = time;
my $counter = 0;
my $row = 1;
my $column = 1;
my %captions;
my $captions_fh;
my $default_caption_text = q(Click outside the image or the "X" );
$default_caption_text .= q(to the lower right to close);
# read in photo captions, if the file exists
if ( -e q(./captions.txt) ) {
open($captions_fh, q|<:encoding(UTF-8)|, q(./captions.txt));
foreach my $caption_line ( <$captions_fh> ) {
chomp $caption_line;
my ($key, $value) = split(/\|/, $caption_line);
# check for 'undef' $value
$value = $default_caption_text
unless ( defined $value );
$captions{$key} = $value;
}
}
my $header_text;
if ( exists($captions{header}) ) {
$header_text = $captions{header};
} else {
$header_text = "This is the default header text"
}
# open the output file 'index.html'
open (OUT, "> index.html");
my $head = <<EOHEAD;
<html>
<head>
<title>Thumbnail Page</title>
<link rel="stylesheet" href="css/lightbox.min.css">
<style>
body {
background-color: #332200;
color: white;
}
h1 {
color: white;
}
</style>
</head>
<body>
<section>
<h3>$header_text</h3>
<p>Click on any of the images below to view the images in a lightbox.</p>
<p>Once the lightbox has been opened, click anywhere outside the image, or
click on the "X" symbol in the lower right corner of the lightbox to
close.</p>
<div>
EOHEAD
print OUT $head;
foreach my $filename (@filedir) {
next if ( $filename =~ /\.sm\.jpg/g );
print "File: $filename - ";
my $caption_text;
if ( exists $captions{$filename} ) {
print qq(Using ѕupplied caption; );
$caption_text = $captions{$filename};
} else {
print qq(Applying default caption; );
if ( exists $captions{default} ) {
$caption_text = $captions{default};
} else {
$caption_text = $default_caption_text;
}
}
my $sm_name = $filename;
$sm_name =~ s/\.jpg$/.sm.jpg/;
print "Resizing $filename to $sm_name\n";
qx(convert -resize 300 $filename $sm_name);
my $img_link = <<EOIMG;
<a href="$filename" data-lightbox="pix" data-title="$caption_text">
<img src="$sm_name" alt="" /></a>
EOIMG
print OUT $img_link;
}
my $tail = <<EOTAIL;
</div>
</section>
<script src="js/lightbox-plus-jquery.min.js"></script>
</body>
</html>
EOTAIL
print OUT $tail;