wax_iiif 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iiif_s3/builder.rb +23 -36
- data/lib/iiif_s3/config.rb +11 -11
- data/lib/iiif_s3/full_image.rb +3 -3
- data/lib/iiif_s3/image_variant.rb +18 -17
- data/lib/iiif_s3/thumbnail.rb +8 -9
- data/spec/iiif_s3/image_variant_spec.rb +10 -13
- data/wax_iiif.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31844c9c4c8aa58c1e5e940fd0bc447c073e0b4e1e5bf8f7dc77970eeaac95b5
|
4
|
+
data.tar.gz: d17b64b8d0f9a6c69340128571128c74bb44c26fb119911aff496dd71a4abc5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8b751aaa0cc21122743f4a2a6f7d166cac8cc7bb36942c631cae2343d382973fe2400282dc1c9e884dc4b9b4902ef8b42fa50a214c69b315a0168c29390b334
|
7
|
+
data.tar.gz: 7ee23f85b57d3ee86abe9002220b73a5138a950dc94406499d2fa59bd7824c56cab91682cd6dc94d8aa311a185e28e774ea2c09e139269c9866324eb5ae0cc15
|
data/lib/iiif_s3/builder.rb
CHANGED
@@ -7,7 +7,7 @@ module IiifS3
|
|
7
7
|
include Utilities::Helpers
|
8
8
|
|
9
9
|
HEADER_VAL = 'filename'
|
10
|
-
|
10
|
+
|
11
11
|
#
|
12
12
|
# @!attribute [r] data
|
13
13
|
# @return [Array<Hash>] The raw data computed for the given set of images
|
@@ -27,7 +27,7 @@ module IiifS3
|
|
27
27
|
# @param [Hash] config an optional configuration object.
|
28
28
|
# @see IiifS3::Config
|
29
29
|
# @return [Void]
|
30
|
-
#
|
30
|
+
#
|
31
31
|
def initialize(config = {})
|
32
32
|
@manifests = []
|
33
33
|
@config = IiifS3::Config.new(config)
|
@@ -35,23 +35,23 @@ module IiifS3
|
|
35
35
|
|
36
36
|
|
37
37
|
#
|
38
|
-
# Load data into the IIIF builder.
|
39
|
-
#
|
38
|
+
# Load data into the IIIF builder.
|
39
|
+
#
|
40
40
|
# This will load the data, perform some basic verifications on it, and sort
|
41
41
|
# it into proper order.
|
42
42
|
#
|
43
|
-
# @param [Array<ImageRecord>, ImageRecord] data
|
43
|
+
# @param [Array<ImageRecord>, ImageRecord] data
|
44
44
|
# Either a single ImageRecord or an Array of ImageRecords.
|
45
|
-
# @raise [IiifS3::Error::InvalidImageData] if any of the data does
|
45
|
+
# @raise [IiifS3::Error::InvalidImageData] if any of the data does
|
46
46
|
# not pass the validation checks
|
47
|
-
#
|
47
|
+
#
|
48
48
|
# @return [Void]
|
49
|
-
#
|
49
|
+
#
|
50
50
|
def load(data)
|
51
51
|
@data = [data].flatten # handle hashes and arrays of hashes
|
52
52
|
|
53
53
|
# validate
|
54
|
-
@data.each do |image_record|
|
54
|
+
@data.each do |image_record|
|
55
55
|
raise IiifS3::Error::InvalidImageData, "Image record #{image_record.inspect} is not an ImageRecord" unless image_record.is_a? ImageRecord
|
56
56
|
raise IiifS3::Error::InvalidImageData, "Image record #{image_record.inspect} does not have an ID and/or a page number" if image_record.id.nil? || image_record.page_number.nil?
|
57
57
|
end
|
@@ -64,16 +64,16 @@ module IiifS3
|
|
64
64
|
# @param [Boolean] force_image_generation Generate images even if they already exist
|
65
65
|
#
|
66
66
|
# @return [Void]
|
67
|
-
#
|
67
|
+
#
|
68
68
|
def process_data(force_image_generation=false)
|
69
69
|
return nil if @data.nil? # do nothing without data.
|
70
70
|
@manifests = []
|
71
71
|
|
72
72
|
resources = {}
|
73
73
|
@data.each do |image_record|
|
74
|
-
|
74
|
+
|
75
75
|
# image generation
|
76
|
-
#
|
76
|
+
#
|
77
77
|
# It attempts to load the info files and skip generation — not currently working.
|
78
78
|
info_file = image_info_file_name(image_record)
|
79
79
|
if (File.exist?(info_file) && !force_image_generation)
|
@@ -91,11 +91,11 @@ module IiifS3
|
|
91
91
|
|
92
92
|
# Generate the manifests
|
93
93
|
resources.each do |key, val|
|
94
|
-
manifests.push generate_manifest(val, @config)
|
94
|
+
manifests.push generate_manifest(val, @config)
|
95
95
|
end
|
96
96
|
|
97
97
|
generate_collection
|
98
|
-
end
|
98
|
+
end
|
99
99
|
|
100
100
|
def generate_collection(label="top")
|
101
101
|
collection = Collection.new(label,@config)
|
@@ -119,14 +119,14 @@ module IiifS3
|
|
119
119
|
#
|
120
120
|
# @return [Void]
|
121
121
|
# @todo Fix this to use the correct data format!
|
122
|
-
#
|
122
|
+
#
|
123
123
|
def load_csv(csv_path)
|
124
124
|
raise Error::InvalidCSV unless File.exist? csv_path
|
125
125
|
begin
|
126
126
|
vals = CSV.read(csv_path)
|
127
127
|
rescue CSV::MalformedCSVError
|
128
128
|
raise Error::InvalidCSV
|
129
|
-
end
|
129
|
+
end
|
130
130
|
|
131
131
|
raise Error::BlankCSV if vals.length == 0
|
132
132
|
raise Error::InvalidCSV if vals[0].length != 3
|
@@ -141,7 +141,7 @@ module IiifS3
|
|
141
141
|
"label" => data[2]
|
142
142
|
}
|
143
143
|
end
|
144
|
-
end
|
144
|
+
end
|
145
145
|
|
146
146
|
protected
|
147
147
|
|
@@ -162,7 +162,7 @@ module IiifS3
|
|
162
162
|
return {"full" => full, "thumbnail" => thumbnail}
|
163
163
|
end
|
164
164
|
|
165
|
-
def generate_tiles(data, config)
|
165
|
+
def generate_tiles(data, config)
|
166
166
|
width = data.variants["full"].width
|
167
167
|
tile_width = config.tile_width
|
168
168
|
height = data.variants["full"].height
|
@@ -186,7 +186,7 @@ module IiifS3
|
|
186
186
|
tile[:xSize] = (tile[:width]/(s*1.0)).ceil
|
187
187
|
end
|
188
188
|
if (tile[:y] + tile[:height] > height)
|
189
|
-
tile[:height] = height - tile[:y]
|
189
|
+
tile[:height] = height - tile[:y]
|
190
190
|
tile[:ySize] = (tile[:height]/(s*1.0)).ceil
|
191
191
|
end
|
192
192
|
tiles.push(tile)
|
@@ -202,14 +202,14 @@ module IiifS3
|
|
202
202
|
"#{generate_image_location(data.id,data.page_number)}/info.json"
|
203
203
|
end
|
204
204
|
|
205
|
-
def generate_image_json(data, config)
|
205
|
+
def generate_image_json(data, config)
|
206
206
|
filename = image_info_file_name(data)
|
207
207
|
info = ImageInfo.new(data.variants["full"].id, data.variants ,config.tile_width, config.tile_scale_factors)
|
208
208
|
|
209
209
|
puts "writing #{filename}" if config.verbose?
|
210
210
|
Pathname.new(Pathname.new(filename).dirname).mkpath
|
211
211
|
File.open(filename, "w") do |file|
|
212
|
-
file.puts info.to_json
|
212
|
+
file.puts info.to_json
|
213
213
|
end
|
214
214
|
if @config.upload_to_s3
|
215
215
|
add_file_to_s3(filename)
|
@@ -225,19 +225,6 @@ module IiifS3
|
|
225
225
|
return m
|
226
226
|
end
|
227
227
|
|
228
|
-
def build_a_manifest
|
229
|
-
|
230
|
-
manifest_uri = "@config.s3.bucket/#{generate_id(record)}/manifest.json"
|
231
|
-
# response = Typhoeus.get(manifest_uri, followlocation: true)
|
232
|
-
# if response.code == 200
|
233
|
-
# puts "Skipping #{file}—Manifest already exists." if verbose
|
234
|
-
# data = JSON.parse(response.body)
|
235
|
-
# obj = IiifS3::FakeManifest.new(data["@id"], data["@type"], data["label"])
|
236
|
-
# @iiif.manifests.push(obj)
|
237
|
-
# next
|
238
|
-
# end
|
239
|
-
end
|
240
|
-
|
241
228
|
|
242
229
|
def generate_variants(data, config)
|
243
230
|
obj = {
|
@@ -246,9 +233,9 @@ module IiifS3
|
|
246
233
|
}
|
247
234
|
|
248
235
|
config.variants.each do |key,image_size|
|
249
|
-
obj[key] = ImageVariant.new(data, config, image_size
|
236
|
+
obj[key] = ImageVariant.new(data, config, image_size)
|
250
237
|
end
|
251
238
|
return obj
|
252
239
|
end
|
253
240
|
end
|
254
|
-
end
|
241
|
+
end
|
data/lib/iiif_s3/config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module IiifS3
|
2
|
-
|
2
|
+
|
3
3
|
# Config provides a data structure for holding the configuration settings
|
4
|
-
# for the IiifS3 class.
|
4
|
+
# for the IiifS3 class.
|
5
5
|
#
|
6
6
|
# @author David Newbury <david.newbury@gmail.com>
|
7
7
|
#
|
@@ -9,7 +9,7 @@ module IiifS3
|
|
9
9
|
|
10
10
|
# @return [String] The default URL to append to all IDs.
|
11
11
|
DEFAULT_URL = "http://0.0.0.0"
|
12
|
-
# @return [String] The name of the subdirectory where generated images live
|
12
|
+
# @return [String] The name of the subdirectory where generated images live
|
13
13
|
DEFAULT_IMAGE_DIRECTORY_NAME = "images"
|
14
14
|
# @return [String] The default path for writing generated image files
|
15
15
|
DEFAULT_OUTPUT_DIRECTORY = "./build"
|
@@ -18,7 +18,7 @@ module IiifS3
|
|
18
18
|
# @return [Array<Number>] The default tile scaling factors
|
19
19
|
DEFAULT_TILE_SCALE_FACTORS = [1,2,4,8]
|
20
20
|
# @return [Number] The default thumbnail size in pixels
|
21
|
-
DEFAULT_THUMBNAIL_SIZE = 250
|
21
|
+
DEFAULT_THUMBNAIL_SIZE = 250
|
22
22
|
|
23
23
|
#
|
24
24
|
# @!attribute [r] base_url
|
@@ -87,7 +87,7 @@ module IiifS3
|
|
87
87
|
|
88
88
|
# Initialize a new configuration option.
|
89
89
|
#
|
90
|
-
# @param [Hash] opts
|
90
|
+
# @param [Hash] opts
|
91
91
|
# @option opts [Boolean] :upload_to_s3 if true, images and metadata will be
|
92
92
|
# uploaded to Amazon S3. Defaults to False.
|
93
93
|
# @option opts [Number] :tile_width The width in pixels for generated tiles.
|
@@ -99,11 +99,11 @@ module IiifS3
|
|
99
99
|
# @option opts [String] :output_dir The name of the directory for generated files.
|
100
100
|
# image data. Defaults to {DEFAULT_OUTPUT_DIRECTORY}
|
101
101
|
# @option opts [String] :base_url The base URL for the generated URIs. Defaults to
|
102
|
-
# {DEFAULT_URL} if not auto-uploading to S3 and to the s3 bucket if upload_to_s3 is enabled.
|
102
|
+
# {DEFAULT_URL} if not auto-uploading to S3 and to the s3 bucket if upload_to_s3 is enabled.
|
103
103
|
# @option opts [Number] :thumbnail_size the size in pixels
|
104
104
|
# for the largest side of the thumbnail images. Defaults to {DEFAULT_THUMBNAIL_SIZE}.
|
105
|
-
# @option opts [Bool] :use_extensions (true) should files have exensions appended?
|
106
|
-
# @option opts [Bool] :verbose (false) Should debug information be printed to the console?
|
105
|
+
# @option opts [Bool] :use_extensions (true) should files have exensions appended?
|
106
|
+
# @option opts [Bool] :verbose (false) Should debug information be printed to the console?
|
107
107
|
# @option opts [String] :prefix ("") a prefix (read: subdirectory) for the generated URIs.
|
108
108
|
# @option opts [Hash{String: String}] :variants
|
109
109
|
def initialize(opts = {})
|
@@ -120,7 +120,7 @@ module IiifS3
|
|
120
120
|
@verbose = opts.fetch(:verbose, false) ## false
|
121
121
|
@prefix = opts[:prefix] || ""
|
122
122
|
if @prefix.length > 0 && @prefix[0] != "/"
|
123
|
-
@prefix = "/#{@prefix}"
|
123
|
+
@prefix = "/#{@prefix}"
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -130,7 +130,7 @@ module IiifS3
|
|
130
130
|
# @param [IiifS3::Config] other_config The configuration file to compare
|
131
131
|
#
|
132
132
|
# @return [Bool] True if they are the same, false otherwise
|
133
|
-
#
|
133
|
+
#
|
134
134
|
def ==(other_config)
|
135
135
|
valid = true
|
136
136
|
self.instance_variables.each do |v|
|
@@ -139,4 +139,4 @@ module IiifS3
|
|
139
139
|
valid
|
140
140
|
end
|
141
141
|
end
|
142
|
-
end
|
142
|
+
end
|
data/lib/iiif_s3/full_image.rb
CHANGED
@@ -9,7 +9,7 @@ module IiifS3
|
|
9
9
|
|
10
10
|
#
|
11
11
|
# Class ImageVariant represents a single image file within a manifest.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
#
|
14
14
|
# @author David Newbury <david.newbury@gmail.com>
|
15
15
|
#
|
@@ -18,10 +18,10 @@ module IiifS3
|
|
18
18
|
include MiniMagick
|
19
19
|
|
20
20
|
#
|
21
|
-
# Initializing an ImageVariant will create the actual image file
|
22
|
-
# on the file system.
|
23
|
-
#
|
24
|
-
# To initialize an image, you will need the
|
21
|
+
# Initializing an ImageVariant will create the actual image file
|
22
|
+
# on the file system.
|
23
|
+
#
|
24
|
+
# To initialize an image, you will need the
|
25
25
|
# data hash to have an "id", a "image_path", and a "page_number".
|
26
26
|
#
|
27
27
|
# @param [Hash] data A Image Data object.
|
@@ -29,15 +29,15 @@ module IiifS3
|
|
29
29
|
# @param [Number] width the desired width of this object in pixels
|
30
30
|
# @param [Number] height the desired height of this object in pixels
|
31
31
|
# @raise IiifS3::Error::InvalidImageData
|
32
|
-
#
|
33
|
-
def initialize(data, config,
|
32
|
+
#
|
33
|
+
def initialize(data, config, size = nil)
|
34
34
|
|
35
35
|
@config = config
|
36
36
|
# Validate input data
|
37
37
|
if data.id.nil? || data.id.to_s.empty?
|
38
|
-
raise IiifS3::Error::InvalidImageData, "Each image needs an ID"
|
38
|
+
raise IiifS3::Error::InvalidImageData, "Each image needs an ID"
|
39
39
|
elsif data.image_path.nil? || data.image_path.to_s.empty?
|
40
|
-
raise IiifS3::Error::InvalidImageData, "Each image needs an path."
|
40
|
+
raise IiifS3::Error::InvalidImageData, "Each image needs an path."
|
41
41
|
end
|
42
42
|
|
43
43
|
# open image
|
@@ -47,7 +47,8 @@ module IiifS3
|
|
47
47
|
raise IiifS3::Error::InvalidImageData, "Cannot read this image file: #{data.image_path}. #{e}"
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
width = size.nil? ? width : size
|
51
|
+
resize(width)
|
51
52
|
@image.format "jpg"
|
52
53
|
|
53
54
|
@id = generate_image_id(data.id,data.page_number)
|
@@ -68,7 +69,7 @@ module IiifS3
|
|
68
69
|
|
69
70
|
#
|
70
71
|
# @!attribute [r] id
|
71
|
-
# @return [String] The URI for the variant.
|
72
|
+
# @return [String] The URI for the variant.
|
72
73
|
attr_reader :id
|
73
74
|
|
74
75
|
|
@@ -89,10 +90,10 @@ module IiifS3
|
|
89
90
|
end
|
90
91
|
|
91
92
|
#
|
92
|
-
# Get the MIME Content-Type of the image.
|
93
|
+
# Get the MIME Content-Type of the image.
|
93
94
|
#
|
94
95
|
# @return [String] the MIME Content-Type (typically "image/jpeg")
|
95
|
-
#
|
96
|
+
#
|
96
97
|
def mime_type
|
97
98
|
@image.mime_type
|
98
99
|
end
|
@@ -103,7 +104,7 @@ module IiifS3
|
|
103
104
|
# @param [String, Number] page_number The page number for this particular image.
|
104
105
|
#
|
105
106
|
# @return [<type>] <description>
|
106
|
-
#
|
107
|
+
#
|
107
108
|
def generate_image_id(id, page_number)
|
108
109
|
"#{@config.base_url}#{@config.prefix}/#{@config.image_directory_name}/#{id}-#{page_number}"
|
109
110
|
end
|
@@ -114,8 +115,8 @@ module IiifS3
|
|
114
115
|
"full"
|
115
116
|
end
|
116
117
|
|
117
|
-
def resize(width
|
118
|
-
@image.resize "#{width}
|
118
|
+
def resize(width)
|
119
|
+
@image.resize "#{width}"
|
119
120
|
end
|
120
121
|
|
121
122
|
def filestring
|
@@ -123,4 +124,4 @@ module IiifS3
|
|
123
124
|
end
|
124
125
|
|
125
126
|
end
|
126
|
-
end
|
127
|
+
end
|
data/lib/iiif_s3/thumbnail.rb
CHANGED
@@ -12,24 +12,23 @@ module IiifS3
|
|
12
12
|
#
|
13
13
|
class Thumbnail < ImageVariant
|
14
14
|
|
15
|
-
# Initialize a new thumbnail.
|
15
|
+
# Initialize a new thumbnail.
|
16
16
|
#
|
17
17
|
# @param [hash] data The image data object
|
18
18
|
# @param [Hash] config The configuration hash
|
19
19
|
# @param [Integer] max_width The maximum width of the thumbnail
|
20
20
|
# @param [Integer] max_height The maximum height of the thumbnail
|
21
|
-
#
|
22
|
-
def initialize(data, config,
|
23
|
-
@
|
24
|
-
@max_height = max_height || config.thumbnail_size
|
21
|
+
#
|
22
|
+
def initialize(data, config, width=nil)
|
23
|
+
@width = width || config.thumbnail_size
|
25
24
|
super(data,config)
|
26
25
|
end
|
27
26
|
|
28
27
|
protected
|
29
28
|
|
30
|
-
def resize(width
|
31
|
-
@image.resize "#{@
|
29
|
+
def resize(width)
|
30
|
+
@image.resize "#{@width}"
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
end
|
35
|
-
end
|
34
|
+
end
|
@@ -7,7 +7,7 @@ describe IiifS3::ImageVariant do
|
|
7
7
|
"id" => 1,
|
8
8
|
"page_number" => 1
|
9
9
|
}) }
|
10
|
-
|
10
|
+
|
11
11
|
context "initialization errors" do
|
12
12
|
it "raises if the image does not have an ID" do
|
13
13
|
data.id =nil
|
@@ -33,23 +33,20 @@ describe IiifS3::ImageVariant do
|
|
33
33
|
"page_number" => 1
|
34
34
|
})
|
35
35
|
config = IiifS3::Config.new
|
36
|
-
@img = IiifS3::ImageVariant.new(data, config, 100
|
36
|
+
@img = IiifS3::ImageVariant.new(data, config, 100)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "has a uri" do
|
40
|
-
expect(@img.uri).to eq("#{@img.generate_image_id(1,1)}/full/
|
41
|
-
end
|
40
|
+
expect(@img.uri).to eq("#{@img.generate_image_id(1,1)}/full/100,/0/default.jpg")
|
41
|
+
end
|
42
42
|
it "has an id" do
|
43
43
|
expect(@img.id).to eq("#{@img.generate_image_id(1,1)}")
|
44
|
-
end
|
44
|
+
end
|
45
45
|
it "has a width" do
|
46
|
-
expect(@img.width).to eq(
|
47
|
-
end
|
48
|
-
it "has a height" do
|
49
|
-
expect(@img.height).to eq(100)
|
50
|
-
end
|
46
|
+
expect(@img.width).to eq(100)
|
47
|
+
end
|
51
48
|
it "has a mime type" do
|
52
|
-
expect(@img.mime_type).to eq("image/jpeg")
|
49
|
+
expect(@img.mime_type).to eq("image/jpeg")
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
@@ -68,4 +65,4 @@ describe IiifS3::ImageVariant do
|
|
68
65
|
end
|
69
66
|
|
70
67
|
end
|
71
|
-
end
|
68
|
+
end
|
data/wax_iiif.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "wax_iiif"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["Marii Nyrop", "David Newbury"]
|
9
9
|
spec.email = ["m.nyrop@columbia.edu"]
|
10
10
|
spec.summary = "Minimal iiif level 0 generator – i.e. David Newbury's iiif_s3 minus s3."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wax_iiif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marii Nyrop
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|