assembly-image 1.7.7 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +22 -0
- data/.github/pull_request_template.md +10 -0
- data/.gitignore +4 -1
- data/.rubocop.yml +150 -3
- data/.rubocop_todo.yml +68 -0
- data/README.md +1 -1
- data/assembly-image.gemspec +2 -0
- data/lib/assembly-image/image.rb +11 -156
- data/lib/assembly-image/jp2_creator.rb +182 -0
- data/lib/assembly-image/version.rb +2 -2
- data/spec/assembly/image/jp2_creator_spec.rb +58 -0
- data/spec/image_spec.rb +248 -244
- data/spec/images_spec.rb +20 -22
- data/spec/spec_helper.rb +84 -0
- metadata +28 -8
- data/.travis.yml +0 -37
data/spec/image_spec.rb
CHANGED
@@ -2,274 +2,278 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@ai = Assembly::Image.new('')
|
9
|
-
expect{ @ai.create_jp2 }.to raise_error
|
10
|
-
end
|
5
|
+
RSpec.describe Assembly::Image do
|
6
|
+
let(:ai) { described_class.new(input_path) }
|
7
|
+
let(:input_path) { TEST_TIF_INPUT_FILE }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
after do
|
10
|
+
# after each test, empty out the input and output test directories
|
11
|
+
remove_files(TEST_INPUT_DIR)
|
12
|
+
remove_files(TEST_OUTPUT_DIR)
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
describe '#jp2_filename' do
|
16
|
+
it 'indicates the default jp2 filename' do
|
17
|
+
expect(ai.jp2_filename).to eq TEST_TIF_INPUT_FILE.gsub('.tif', '.jp2')
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
expect(@ai.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif', '.jp2').gsub('_00_', '_05_')
|
25
|
-
end
|
20
|
+
context 'with a file with no extension' do
|
21
|
+
let(:input_path) { '/path/to/a/file_with_no_extension' }
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
it 'indicates the default jp2 filename' do
|
24
|
+
expect(ai.jp2_filename).to eq '/path/to/a/file_with_no_extension.jp2'
|
25
|
+
end
|
26
|
+
end
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
36
|
-
# @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
37
|
-
# result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
38
|
-
# # Indicates a temp tiff was not created.
|
39
|
-
# expect(@ai.tmp_path).to be_nil
|
40
|
-
# expect(result).to be_a_kind_of Assembly::Image
|
41
|
-
# expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
42
|
-
# expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
43
|
-
# expect(result.exif.colorspace).to eq 'sRGB'
|
44
|
-
# @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
45
|
-
# expect(@jp2.height).to eq 100
|
46
|
-
# expect(@jp2.width).to eq 100
|
47
|
-
# end
|
48
|
-
|
49
|
-
it 'creates the jp2 with a temp file when given an LZW compressed RGB tif' do
|
50
|
-
generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw')
|
51
|
-
expect(File).to exist TEST_TIF_INPUT_FILE
|
52
|
-
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
53
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
54
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
55
|
-
# Indicates a temp tiff was not created.
|
56
|
-
expect(@ai.tmp_path).to_not be_nil
|
57
|
-
expect(result).to be_a_kind_of Assembly::Image
|
58
|
-
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
59
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
60
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
61
|
-
@jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
62
|
-
expect(@jp2.height).to eq 100
|
63
|
-
expect(@jp2.width).to eq 100
|
64
|
-
end
|
29
|
+
describe '#dpg_jp2_filename' do
|
30
|
+
context 'with a dpg tiff file' do
|
31
|
+
let(:input_path) { TEST_DPG_TIF_INPUT_FILE }
|
65
32
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
71
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
72
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
73
|
-
expect(@ai.tmp_path).to_not be_nil
|
74
|
-
expect(result).to be_a_kind_of Assembly::Image
|
75
|
-
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
76
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
77
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
78
|
-
@jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
79
|
-
expect(@jp2.height).to eq 37_838
|
80
|
-
expect(@jp2.width).to eq 37_838
|
81
|
-
end
|
33
|
+
it 'indicates the default DPG jp2 filename' do
|
34
|
+
expect(ai.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif', '.jp2').gsub('_00_', '_05_')
|
35
|
+
end
|
36
|
+
end
|
82
37
|
|
83
|
-
|
84
|
-
|
85
|
-
generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw', width: '37838', height: '37838')
|
86
|
-
expect(File).to exist TEST_TIF_INPUT_FILE
|
87
|
-
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
88
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
89
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
90
|
-
expect(@ai.tmp_path).to_not be_nil
|
91
|
-
expect(result).to be_a_kind_of Assembly::Image
|
92
|
-
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
93
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
94
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
95
|
-
@jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
96
|
-
expect(@jp2.height).to eq 37_838
|
97
|
-
expect(@jp2.width).to eq 37_838
|
98
|
-
end
|
38
|
+
context 'with a file with no extension' do
|
39
|
+
let(:input_path) { '/path/to/a/file_with_no_00_extension' }
|
99
40
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
105
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
106
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
107
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
108
|
-
expect(result.exif.colorspace).to eq 'Grayscale'
|
41
|
+
it 'indicates the default jp2 filename' do
|
42
|
+
expect(ai.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
|
43
|
+
end
|
44
|
+
end
|
109
45
|
end
|
110
46
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
expect(File).to_not exist TEST_JP2_OUTPUT_FILE
|
115
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
116
|
-
expect(@ai).to_not have_color_profile
|
117
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
118
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
119
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
120
|
-
end
|
47
|
+
describe '#create_jp2' do
|
48
|
+
context 'when input path is blank' do
|
49
|
+
let(:input_path) { '' }
|
121
50
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
127
|
-
# Indicates a temp tiff was not created.
|
128
|
-
expect(@ai.tmp_path).to be_nil
|
129
|
-
expect(@ai).to_not have_color_profile
|
130
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
131
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
132
|
-
expect(result.exif.colorspace).to eq 'Grayscale'
|
133
|
-
end
|
51
|
+
it 'does not run if no input file is passed in' do
|
52
|
+
expect { ai.create_jp2 }.to raise_error
|
53
|
+
end
|
54
|
+
end
|
134
55
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
140
|
-
# Indicates a temp tiff was not created.
|
141
|
-
expect(@ai.tmp_path).to be_nil
|
142
|
-
expect(@ai).to_not have_color_profile
|
143
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
144
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
145
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
146
|
-
end
|
56
|
+
context 'when given an uncompressed compressed RGB tif with more than 4GB of image data', skip: 'This test will create a 4GB test image and a 4GB temporary image, so skipping by default.' do
|
57
|
+
before do
|
58
|
+
generate_test_image(TEST_TIF_INPUT_FILE, compress: 'none', width: '37838', height: '37838')
|
59
|
+
end
|
147
60
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
61
|
+
it 'creates the jp2 with a temp file' do
|
62
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
63
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
64
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
65
|
+
expect(ai.tmp_path).not_to be_nil
|
66
|
+
expect(result).to be_a_kind_of described_class
|
67
|
+
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
68
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
69
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
70
|
+
jp2 = described_class.new(TEST_JP2_OUTPUT_FILE)
|
71
|
+
expect(jp2.height).to eq 37_838
|
72
|
+
expect(jp2.width).to eq 37_838
|
73
|
+
end
|
74
|
+
end
|
161
75
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
167
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
168
|
-
expect{ @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE) }.to raise_error(SecurityError)
|
169
|
-
end
|
76
|
+
context 'when given an LZW compressed RGB tif with more than 4GB of image data', skip: 'This test will create a 4GB temporary image, so skipping by default.' do
|
77
|
+
before do
|
78
|
+
generate_test_image(TEST_TIF_INPUT_FILE, compress: 'lzw', width: '37838', height: '37838')
|
79
|
+
end
|
170
80
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
81
|
+
it 'creates the jp2 with a temp file' do
|
82
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
83
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
84
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
85
|
+
expect(ai.tmp_path).not_to be_nil
|
86
|
+
expect(result).to be_a_kind_of described_class
|
87
|
+
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
88
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
89
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
90
|
+
jp2 = described_class.new(TEST_JP2_OUTPUT_FILE)
|
91
|
+
expect(jp2.height).to eq 37_838
|
92
|
+
expect(jp2.width).to eq 37_838
|
93
|
+
end
|
94
|
+
end
|
177
95
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
# Indicates a temp tiff was not created.
|
184
|
-
expect(@ai.tmp_path).to be_nil
|
185
|
-
expect(@ai).to_not have_color_profile
|
186
|
-
expect(@ai).to be_a_valid_image
|
187
|
-
expect(@ai).to be_jp2able
|
188
|
-
@ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
189
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
190
|
-
@ai = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
|
191
|
-
expect(@ai).to be_valid_image
|
192
|
-
expect(@ai).to_not be_jp2able
|
193
|
-
expect { @ai.create_jp2 }.to raise_error
|
194
|
-
end
|
96
|
+
context 'when given a bitonal tif' do
|
97
|
+
before do
|
98
|
+
# Need to force group4 compression to get ImageMagick to create bitonal tiff
|
99
|
+
generate_test_image(TEST_TIF_INPUT_FILE, image_type: 'Bilevel', compress: 'group4')
|
100
|
+
end
|
195
101
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
205
|
-
end
|
102
|
+
it 'creates grayscale jp2' do
|
103
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
104
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
105
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
106
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
107
|
+
expect(result.exif.colorspace).to eq 'Grayscale'
|
108
|
+
end
|
109
|
+
end
|
206
110
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
@ai = Assembly::Image.new(TEST_JPEG_INPUT_FILE)
|
212
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
213
|
-
# Indicates a temp tiff was created.
|
214
|
-
expect(@ai.tmp_path).not_to be_nil
|
215
|
-
expect(File).not_to exist @ai.tmp_path
|
216
|
-
expect(result).to be_a_kind_of Assembly::Image
|
217
|
-
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
218
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
219
|
-
end
|
111
|
+
context 'when given a color tif but bitonal image data (1 channels and 1 bits per pixel)' do
|
112
|
+
before do
|
113
|
+
generate_test_image(TEST_TIF_INPUT_FILE, color: 'Bilevel', image_type: 'TrueColor', profile: '')
|
114
|
+
end
|
220
115
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
116
|
+
it 'creates color jp2' do
|
117
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
118
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
119
|
+
expect(ai).not_to have_color_profile
|
120
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
121
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
122
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
123
|
+
end
|
124
|
+
end
|
229
125
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE, preserve_tmp_source: true)
|
235
|
-
# Indicates a temp tiff was created.
|
236
|
-
expect(@ai.tmp_path).not_to be_nil
|
237
|
-
expect(File).to exist @ai.tmp_path
|
238
|
-
expect(result).to be_a_kind_of Assembly::Image
|
239
|
-
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
240
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
241
|
-
expect(File.exist?(@ai.tmp_path)).to be true
|
242
|
-
end
|
126
|
+
context 'when given a graycale tif but with bitonal image data (1 channel and 1 bits per pixel)' do
|
127
|
+
before do
|
128
|
+
generate_test_image(TEST_TIF_INPUT_FILE, color: 'Bilevel', image_type: 'Grayscale', profile: '')
|
129
|
+
end
|
243
130
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
254
|
-
end
|
131
|
+
it 'creates grayscale jp2' do
|
132
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
133
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
134
|
+
expect(ai).not_to have_color_profile
|
135
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
136
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
137
|
+
expect(result.exif.colorspace).to eq 'Grayscale'
|
138
|
+
end
|
139
|
+
end
|
255
140
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
261
|
-
@ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
|
262
|
-
result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE, overwrite: true)
|
263
|
-
expect(result).to be_a_kind_of Assembly::Image
|
264
|
-
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
265
|
-
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
266
|
-
expect(result.exif.colorspace).to eq 'sRGB'
|
267
|
-
end
|
141
|
+
context 'when given a color tif but with greyscale image data (1 channel and 8 bits per pixel)' do
|
142
|
+
before do
|
143
|
+
generate_test_image(TEST_TIF_INPUT_FILE, color: 'Grayscale', image_type: 'TrueColor', profile: '')
|
144
|
+
end
|
268
145
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
146
|
+
it 'creates color jp2' do
|
147
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
148
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
149
|
+
expect(ai).not_to have_color_profile
|
150
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
151
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
152
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when the source image has no profile' do
|
157
|
+
before do
|
158
|
+
generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'creates a jp2' do
|
162
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
163
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
164
|
+
expect(ai).not_to have_color_profile
|
165
|
+
expect(ai).to be_a_valid_image
|
166
|
+
expect(ai).to be_jp2able
|
167
|
+
ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
168
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "when the output file exists and you don't allow overwriting" do
|
173
|
+
before do
|
174
|
+
generate_test_image(TEST_TIF_INPUT_FILE)
|
175
|
+
generate_test_image(TEST_JP2_OUTPUT_FILE)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'does not run' do
|
179
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
180
|
+
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
181
|
+
expect { ai.create_jp2(output: TEST_JP2_OUTPUT_FILE) }.to raise_error(SecurityError)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when given a test tiff' do
|
186
|
+
before do
|
187
|
+
generate_test_image(TEST_TIF_INPUT_FILE)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'gets the correct image height and width' do
|
191
|
+
expect(ai.height).to eq 100
|
192
|
+
expect(ai.width).to eq 100
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'when the input file is a jp2' do
|
197
|
+
before do
|
198
|
+
generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'does not run' do
|
202
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
203
|
+
expect(File).not_to exist TEST_JP2_OUTPUT_FILE
|
204
|
+
expect(ai).not_to have_color_profile
|
205
|
+
expect(ai).to be_a_valid_image
|
206
|
+
expect(ai).to be_jp2able
|
207
|
+
ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
|
208
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
209
|
+
jp2_file = described_class.new(TEST_JP2_OUTPUT_FILE)
|
210
|
+
expect(jp2_file).to be_valid_image
|
211
|
+
expect(jp2_file).not_to be_jp2able
|
212
|
+
expect { jp2_file.create_jp2 }.to raise_error
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'when you specify a bogus output profile' do
|
217
|
+
before do
|
218
|
+
generate_test_image(TEST_TIF_INPUT_FILE)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'runs, because this is not currently an option' do
|
222
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
223
|
+
result = ai.create_jp2(output_profile: 'bogusness')
|
224
|
+
expect(result).to be_a_kind_of described_class
|
225
|
+
expect(result.path).to eq TEST_JP2_INPUT_FILE
|
226
|
+
expect(TEST_JP2_INPUT_FILE).to be_a_jp2
|
227
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'when an invalid tmp folder' do
|
232
|
+
before do
|
233
|
+
generate_test_image(TEST_JPEG_INPUT_FILE)
|
234
|
+
end
|
235
|
+
|
236
|
+
let(:input_path) { TEST_JPEG_INPUT_FILE }
|
237
|
+
|
238
|
+
it 'does not run' do
|
239
|
+
bogus_folder = '/crapsticks'
|
240
|
+
expect(File).to exist TEST_JPEG_INPUT_FILE
|
241
|
+
expect(File).not_to exist bogus_folder
|
242
|
+
expect { ai.create_jp2(tmp_folder: bogus_folder) }.to raise_error
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when no output file is specified' do
|
247
|
+
before do
|
248
|
+
generate_test_image(TEST_TIF_INPUT_FILE)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'creates a jp2 of the same filename and in the same location as the input and cleans up the tmp file' do
|
252
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
253
|
+
expect(File.exist?(TEST_JP2_INPUT_FILE)).to be false
|
254
|
+
result = ai.create_jp2
|
255
|
+
expect(result).to be_a_kind_of described_class
|
256
|
+
expect(result.path).to eq TEST_JP2_INPUT_FILE
|
257
|
+
expect(TEST_JP2_INPUT_FILE).to be_a_jp2
|
258
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'when the output file exists and you allow overwriting' do
|
263
|
+
before do
|
264
|
+
generate_test_image(TEST_TIF_INPUT_FILE)
|
265
|
+
generate_test_image(TEST_JP2_OUTPUT_FILE)
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'recreates jp2' do
|
269
|
+
expect(File).to exist TEST_TIF_INPUT_FILE
|
270
|
+
expect(File).to exist TEST_JP2_OUTPUT_FILE
|
271
|
+
result = ai.create_jp2(output: TEST_JP2_OUTPUT_FILE, overwrite: true)
|
272
|
+
expect(result).to be_a_kind_of described_class
|
273
|
+
expect(result.path).to eq TEST_JP2_OUTPUT_FILE
|
274
|
+
expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
|
275
|
+
expect(result.exif.colorspace).to eq 'sRGB'
|
276
|
+
end
|
277
|
+
end
|
273
278
|
end
|
274
279
|
end
|
275
|
-
# rubocop:enable Metrics/BlockLength
|
data/spec/images_spec.rb
CHANGED
@@ -2,48 +2,46 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
RSpec.describe Assembly::Images do
|
6
|
+
after do
|
7
|
+
# after each test, empty out the input and output test directories
|
8
|
+
remove_files(TEST_INPUT_DIR)
|
9
|
+
remove_files(TEST_OUTPUT_DIR)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'does not run if no input folder is passed in' do
|
13
|
+
expect{ described_class.batch_generate_jp2('') }.to raise_error
|
9
14
|
end
|
10
15
|
|
11
|
-
it '
|
12
|
-
expect{
|
16
|
+
it 'does not run if a non-existent input folder is passed in' do
|
17
|
+
expect{ described_class.batch_generate_jp2('/junk/path') }.to raise_error
|
13
18
|
end
|
14
19
|
|
15
|
-
it '
|
20
|
+
it 'runs and batch produces jp2s from input tiffs' do
|
16
21
|
['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
|
17
|
-
|
22
|
+
described_class.batch_generate_jp2(TEST_INPUT_DIR, output: TEST_OUTPUT_DIR)
|
18
23
|
expect(File.directory?(TEST_OUTPUT_DIR)).to be true
|
19
24
|
['test1', 'test2', 'test3'].each { |image| expect(File.join(TEST_OUTPUT_DIR, "#{image}.jp2")).to be_a_jp2 }
|
20
25
|
end
|
21
26
|
|
22
|
-
it '
|
27
|
+
it 'runs and batch add color profile descriptions input tiffs with no color profile descriptions' do
|
23
28
|
['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif"), profile: '') }
|
24
|
-
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to
|
25
|
-
|
29
|
+
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to be_nil }
|
30
|
+
described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998')
|
26
31
|
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'Adobe RGB (1998)' }
|
27
32
|
end
|
28
33
|
|
29
|
-
it '
|
34
|
+
it 'runs and batch add color profile descriptions input tiffs, forcing over existing color profile descriptions' do
|
30
35
|
['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
|
31
36
|
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'sRGB IEC61966-2.1' }
|
32
|
-
|
37
|
+
described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998', force: true) # force overwrite
|
33
38
|
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'Adobe RGB (1998)' }
|
34
39
|
end
|
35
40
|
|
36
|
-
it '
|
41
|
+
it 'runs and batch add color profile descriptions input tiffs, not overwriting existing color profile descriptions' do
|
37
42
|
['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
|
38
43
|
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'sRGB IEC61966-2.1' }
|
39
|
-
|
44
|
+
described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998') # do not force overwrite
|
40
45
|
['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'sRGB IEC61966-2.1' }
|
41
46
|
end
|
42
|
-
|
43
|
-
after(:each) do
|
44
|
-
# after each test, empty out the input and output test directories
|
45
|
-
remove_files(TEST_INPUT_DIR)
|
46
|
-
remove_files(TEST_OUTPUT_DIR)
|
47
|
-
end
|
48
47
|
end
|
49
|
-
# rubocop:enable Metrics/BlockLength
|