-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerateGallery.php
199 lines (164 loc) · 6.25 KB
/
generateGallery.php
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
*
* Created by Cheryl Handsaker.
* User: cph2
* Date: 8/25/17
* Purpose: Generate the digital gallery for the PINK Exhibit from a tsv file provided by WCMA
*
*/
function generateGallerySidecards ()
{
/***
* Takes the rank of the image and returns the filename of the appropriate thumbnail
*
* @param $rank - the rank of the image
*
*/
function chooseThumbnail ($rank) {
$i = ceil ($rank / 100); // round up to the nearest integer
switch ($i) {
case 1:
return ("1-100.png");
break;
case 2:
return ("101-200.png");;
break;
case 3:
return ("201-300.png");
break;
case 4:
return ("301-400.png");
break;
case 5:
return ("401-500.png");
break;
default:
return ("over500.png");
}
}
//Pull exhibit data from tab-separated file into an associative array
$checklistfilename = "data/pinkexhibit.tsv";
$header = null;
$pinkdata = array();
$lines = file($checklistfilename);
foreach ($lines as $line) {
$values = str_getcsv($line, "\t");
if (!$header) $header = $values;
else $pinkdata[] = array_combine($header, $values);
}
//Pull algorithm data from tab-separated file into an associative array
$algorithmfilename = "data/pink-algorithms.tsv";
$header = null;
$pinkalgorithms = array();
$lines = file($algorithmfilename);
foreach ($lines as $line) {
$values = str_getcsv($line, "\t");
if (!$header) $header = $values;
else $pinkalgorithms[] = array_combine($header, $values);
}
// Generate the ready function that contains the gallery scripts for each image
$pinkgallery = '<script type="text/javascript">';
$pinkgallery .= '$(document).ready(function (){ ';
// Generate the lightGallery javascript for each image in the exhibit
foreach ($pinkdata as $pinkimage) {
// Tie the scripts to the html element for each dynamic lightGallery based on the filename
$pinkgallery .= "
$('#_" . preg_replace("/[^A-Za-z0-9 ]/", '', $pinkimage['filename']) . "').on('click', function() {
";
$pinkgallery .= "$(this).lightGallery({
dynamic: true,
dynamicEl: [{";
//Create the entry for the original image
$pinkgallery .= '
"src":' . " 'images/original/" . $pinkimage['filename'] . ".jpg',";
$pinkgallery .= "
'thumb': 'images/thumbs/original.png',";
$pinkgallery .= "
'subHtml': '" . $pinkimage['image-info'] . "'
";
$pinkgallery .= ' }';
// Iterate through each algorith and generate the sidecar image for the lightGallery
foreach ($pinkalgorithms as $algorithm) {
// Sample of the loop generated code
//, {
//"src": 'images/plain/IMG_78.38.31.png',
//'thumb': 'images/thumbs/PinkCircles2.png',
//'subHtml': "<h4>Plain</h4><p>Lots of information about the Plain Algortithm</p>"
// }
// Original are jpg but sidecars are png
$sidecarImage = $algorithm['name'] . "/" . $pinkimage['filename'] .".png";
// Thumbnails are stored in the algorithm directory, prefaced by thumb- and are assumed to be svg images
$rankValue = $algorithm['name']."-rank";
$sidecarThumb = "/thumbs/" . chooseThumbnail($pinkimage[$rankValue]);
$pinkgallery .= ', {
"src": ';
$pinkgallery .= "'images/" . $sidecarImage . "',
'thumb': 'images/" . $sidecarThumb. "',";
$pinkgallery .= "
'subHtml': " . "'" . $algorithm['description'] . "'
}";
}
//Close the script for each image
$pinkgallery .= "],
share: false,
autoplayControls: false,
download: false,
actualSize: false,
fullScreen: false,
toogleThumb: false,
thumbWidth: 50,
thumbHeight: '50px',
thumbContHeight: 70,
loadVimeoThumbnail: false
});
});
";
}
$pinkgallery .= '})
</script>';
echo $pinkgallery;
}
function generateGalleryDisplay ()
{
//Pull exhibit data from tab-separated file into an associative array
$checklistfilename = "data/pinkexhibit.tsv";
$header = null;
$pinkdata = array();
$lines = file($checklistfilename);
foreach ($lines as $line) {
$values = str_getcsv($line, "\t");
if (!$header) $header = $values;
else $pinkdata[] = array_combine($header, $values);
}
//Pull algorithm data from tab-separated file into an associative array
$algorithmfilename = "data/pink-algorithms.tsv";
$header = null;
$pinkalgorithms = array();
$lines = file($algorithmfilename);
foreach ($lines as $line) {
$values = str_getcsv($line, "\t");
if (!$header) $header = $values;
else $pinkalgorithms[] = array_combine($header, $values);
}
// Include the gallery definition
$pinkgallery = '<section class="gallery">';
// Generate the code for the gallery, with sorting and layout
foreach ($pinkdata as $pinkimage) {
$pinkgallery .= '
<article class="pinkart">
<a href="javascript:void(0)" id="_'. preg_replace("/[^A-Za-z0-9 ]/", '', $pinkimage['filename']) .'">
<img src="images/original/'. $pinkimage['filename']. '.jpg " alt="">
</a>
<span class="meanrank">' . $pinkimage['mean-rank'] . '</span>
';
foreach ($pinkalgorithms as $algorithm) {
$rankValue = $algorithm['name']."-rank";
$pinkgallery .= '<span class="'. $algorithm['name'] . 'rank">' . $pinkimage[$rankValue] . '</span>
';
}
$pinkgallery .= '</article>';
}
$pinkgallery .= '</section> <!-- .gallery -->';
echo $pinkgallery;
}