assembly-image 1.8.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/image_spec.rb DELETED
@@ -1,279 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Assembly::Image do
6
- let(:assembly_image) { described_class.new(input_path) }
7
- let(:input_path) { TEST_TIF_INPUT_FILE }
8
-
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)
13
- end
14
-
15
- describe '#jp2_filename' do
16
- it 'indicates the default jp2 filename' do
17
- expect(assembly_image.jp2_filename).to eq TEST_TIF_INPUT_FILE.gsub('.tif', '.jp2')
18
- end
19
-
20
- context 'with a file with no extension' do
21
- let(:input_path) { '/path/to/a/file_with_no_extension' }
22
-
23
- it 'indicates the default jp2 filename' do
24
- expect(assembly_image.jp2_filename).to eq '/path/to/a/file_with_no_extension.jp2'
25
- end
26
- end
27
- end
28
-
29
- describe '#dpg_jp2_filename' do
30
- context 'with a dpg tiff file' do
31
- let(:input_path) { TEST_DPG_TIF_INPUT_FILE }
32
-
33
- it 'indicates the default DPG jp2 filename' do
34
- expect(assembly_image.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif', '.jp2').gsub('_00_', '_05_')
35
- end
36
- end
37
-
38
- context 'with a file with no extension' do
39
- let(:input_path) { '/path/to/a/file_with_no_00_extension' }
40
-
41
- it 'indicates the default jp2 filename' do
42
- expect(assembly_image.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
43
- end
44
- end
45
- end
46
-
47
- describe '#create_jp2' do
48
- context 'when input path is blank' do
49
- let(:input_path) { '' }
50
-
51
- it 'does not run if no input file is passed in' do
52
- expect { assembly_image.create_jp2 }.to raise_error
53
- end
54
- end
55
-
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
60
-
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 = assembly_image.create_jp2(output: TEST_JP2_OUTPUT_FILE)
65
- expect(assembly_image.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
75
-
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
80
-
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 = assembly_image.create_jp2(output: TEST_JP2_OUTPUT_FILE)
85
- expect(assembly_image.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
95
-
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
101
-
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 = assembly_image.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
110
-
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
115
-
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(assembly_image).not_to have_color_profile
120
- result = assembly_image.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
125
-
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
130
-
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(assembly_image).not_to have_color_profile
135
- result = assembly_image.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
140
-
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
145
-
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(assembly_image).not_to have_color_profile
150
- result = assembly_image.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(assembly_image).not_to have_color_profile
165
- expect(assembly_image).to be_a_valid_image
166
- expect(assembly_image).to be_jp2able
167
- assembly_image.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 { assembly_image.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(assembly_image.height).to eq 100
192
- expect(assembly_image.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(assembly_image).not_to have_color_profile
205
- expect(assembly_image).to be_a_valid_image
206
- expect(assembly_image).to be_jp2able
207
- assembly_image.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 = assembly_image.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 { assembly_image.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 = assembly_image.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 = assembly_image.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
278
- end
279
- end
data/spec/images_spec.rb DELETED
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
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
14
- end
15
-
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
18
- end
19
-
20
- it 'runs and batch produces jp2s from input tiffs' do
21
- ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
22
- described_class.batch_generate_jp2(TEST_INPUT_DIR, output: TEST_OUTPUT_DIR)
23
- expect(File.directory?(TEST_OUTPUT_DIR)).to be true
24
- ['test1', 'test2', 'test3'].each { |image| expect(File.join(TEST_OUTPUT_DIR, "#{image}.jp2")).to be_a_jp2 }
25
- end
26
-
27
- it 'runs and batch add color profile descriptions input tiffs with no color profile descriptions' do
28
- ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif"), profile: '') }
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')
31
- ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'Adobe RGB (1998)' }
32
- end
33
-
34
- it 'runs and batch add color profile descriptions input tiffs, forcing over existing color profile descriptions' do
35
- ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
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' }
37
- described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998', force: true) # force overwrite
38
- ['test1', 'test2', 'test3'].each { |image| expect(Assembly::Image.new(File.join(TEST_INPUT_DIR, "#{image}.tif")).exif.profiledescription).to eq 'Adobe RGB (1998)' }
39
- end
40
-
41
- it 'runs and batch add color profile descriptions input tiffs, not overwriting existing color profile descriptions' do
42
- ['test1', 'test2', 'test3'].each { |image| generate_test_image(File.join(TEST_INPUT_DIR, "#{image}.tif")) }
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' }
44
- described_class.batch_add_exif_profile_descr(TEST_INPUT_DIR, 'Adobe RGB 1998') # do not force overwrite
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' }
46
- end
47
- end