-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.rb
executable file
·80 lines (66 loc) · 1.86 KB
/
test.rb
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
require 'dotenv'
Dotenv.load
require 'rmagick'
require_relative 'lib/iiif_s3'
# Set up configuration variables
opts = {}
opts[:image_directory_name] = "img"
opts[:output_dir] = "/Users/david/Documents/opensource/mirador"
opts[:variants] = { "reference" => 600, "access" => 1200}
opts[:upload_to_s3] = true
opts[:image_types] = [".jpg", ".tif", ".jpeg", ".tiff"]
opts[:document_file_types] = [".pdf"]
# Setup Temporary stores
@data = []
@cleanup_list = []
@dir = "./data"
def add_image(file, is_doc = false)
name = File.basename(file, File.extname(file))
name_parts = name.split("_")
is_paged = name_parts.length == 8
page_num = is_paged ? name_parts[7].to_i : 1
name_parts.pop if is_paged
id = name_parts.join("_")
obj = {
"path" => "#{file}",
"id" => id,
"label" => name_parts.join("."),
"is_master" => page_num == 1,
"page_number" => page_num,
"is_document" => false,
"description" => "This is a test file generated as part of the development on the ruby IiifS3 Gem. <b> This should be bold.</b>"
}
if is_paged
obj["section"] = "p#{page_num}"
obj["section_label"] = "Page #{page_num}"
end
if is_doc
obj["is_document"] = true
end
@data.push IiifS3::ImageRecord.new(obj)
end
def add_to_cleanup_list(img)
@cleanup_list.push(img)
end
def cleanup
@cleanup_list.each do |file|
File.delete(file)
end
end
iiif = IiifS3::Builder.new(opts)
iiif.create_build_directories
Dir.foreach(@dir) do |file|
if opts[:image_file_types].include? File.extname(file)
add_image("#{@dir}/#{file}")
elsif opts[:document_file_types].include? File.extname(file)
path = "#{@dir}/#{file}"
images = IiifS3::Utilities::PdfSplitter.split(path)
images.each do |img|
add_image(img, true)
add_to_cleanup_list(img)
end
end
end
iiif.load(@data)
iiif.process_data
cleanup