This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
directory-to-iiif-s3.php
79 lines (67 loc) · 1.9 KB
/
directory-to-iiif-s3.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
<?php
// directory-to-iiif-s3.php - convert all the image files in a directory to iiif
require_once('image-to-iiif-s3.php');
function usage() {
global $argv;
echo PHP_EOL;
echo "Usage: php " . $argv[0] . " [--help] [--force] -f /path/to/files -c collection " . PHP_EOL;
echo "--help - show this info" . PHP_EOL;
echo "--force - ignore existing and rewrite all iiif images" . PHP_EOL;
echo "-f - path to local directory of image files" . PHP_EOL;
echo "-c - name of the collection (used in the s3 path)" . PHP_EOL;
exit (0);
}
$log = FALSE;
$options = getopt("f:c:",array("help", "force"));
if (isset($options['help'])) {
usage();
}
$force_replacement = isset($options["force"]);
if (isset($options['f'])) {
$directory = $options['f'];
}
else {
usage();
}
if (isset($options['c'])) {
$collection = $options['c'];
}
else {
usage();
}
try {
$supported_image_formats = array('png', 'jpg', 'gif', 'tif');
if (!is_dir($directory)) {
throw new Exception("Not a directory: $directory", 1);
}
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ('.' === $file) continue;
if ('..' === $file) continue;
$image_url = "$directory/$file";
$path_parts = pathinfo($image_url);
if (!isset($path_parts['extension'])) {
continue;
}
$extension = trim($path_parts['extension']);
if (!in_array($extension, $supported_image_formats)) {
continue;
}
$filename = trim($path_parts['filename']);
if (empty($filename)) {
continue;
}
$s3_path = "$collection/$filename";
print "$image_url -> $s3_path\n";
image_to_iiif_s3($image_url, $extension, $s3_path, $force_replacement);
}
closedir($handle);
}
}
catch (Exception $e) {
$error = 'Caught exception: ' . $e->getMessage() . "\n";
echo $error;
exit (1);
}
exit (0);
?>