assembly-image 2.1.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '088a4b9c59b50f893f7b50c16898321770006b4ab22dc08a8ddd70cdba9a15da'
4
- data.tar.gz: f22bf6d6acbd4d6885e2102526e7c5e0ac76b93af71eff0d2237d32334afd223
3
+ metadata.gz: 46a8b192fe259bee51df21215e413dc0a570012b441f530cabb73a172dfb6e13
4
+ data.tar.gz: a87eb5df0582c60e74c182e8711758df11388a4aaaf9084149a0b1b3bcdaf5a7
5
5
  SHA512:
6
- metadata.gz: 91f0be3622982ad69823a45eca8111d05756e0442cd7d7aa16cb8099e71ee2e95c21f17c7f14b7ccab04c11724233c9a9739e24f8b8302f07f42b16738c6400e
7
- data.tar.gz: d1ab206c475413496a6add9376cb246705df18a3142bdc32189b202e31af698b8cfded84464d00e94357fc08396ab142270043b3b862cc0d68cd57834863b649
6
+ metadata.gz: cdbb16145c19623c462b5a0121dafe614e09d6f37dfd5ca1cde1ea4b38eb3829c0cf33300dbde92f64a3c678e2c313bd5241352a52510499c084061058a2204a
7
+ data.tar.gz: 56d878d05722d07fbb0fe42e8ae04bdb39772ada0c94d03808ba066ef89719a0af0419ceaa667db53030b7385139226ef77a1c3d97bb8d76640f58e3e848a7c0
data/.circleci/config.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  version: 2.1
2
2
  orbs:
3
- ruby-rails: sul-dlss/ruby-rails@3.1.2
3
+ ruby-rails: sul-dlss/ruby-rails@4.1.0
4
4
  workflows:
5
5
  build:
6
6
  jobs:
data/.rubocop.yml CHANGED
@@ -143,7 +143,7 @@ RSpec/IdenticalEqualityAssertion: # new in 2.4
143
143
  Enabled: true
144
144
  RSpec/SubjectDeclaration: # new in 2.5
145
145
  Enabled: true
146
- RSpec/FactoryBot/SyntaxMethods: # new in 2.7
146
+ FactoryBot/SyntaxMethods: # new in 2.7
147
147
  Enabled: true
148
148
  RSpec/Rails/AvoidSetupHook: # new in 2.4
149
149
  Enabled: false
@@ -180,7 +180,106 @@ Lint/ConstantOverwrittenInRescue: # new in 1.31
180
180
  Lint/NonAtomicFileOperation: # new in 1.31
181
181
  Enabled: true
182
182
 
183
- RSpec/Capybara/SpecificMatcher: # new in 2.12
183
+ Capybara/SpecificMatcher: # new in 2.12
184
184
  Enabled: true
185
185
  RSpec/Rails/HaveHttpStatus: # new in 2.12
186
186
  Enabled: false
187
+
188
+ Gemspec/DevelopmentDependencies: # new in 1.44
189
+ Enabled: false
190
+ Lint/DuplicateMagicComment: # new in 1.37
191
+ Enabled: true
192
+ Lint/DuplicateMatchPattern: # new in 1.50
193
+ Enabled: true
194
+ Lint/RequireRangeParentheses: # new in 1.32
195
+ Enabled: true
196
+ Lint/UselessRescue: # new in 1.43
197
+ Enabled: true
198
+ Metrics/CollectionLiteralLength: # new in 1.47
199
+ Enabled: true
200
+ Style/ArrayIntersect: # new in 1.40
201
+ Enabled: true
202
+ Style/ComparableClamp: # new in 1.44
203
+ Enabled: true
204
+ Style/ConcatArrayLiterals: # new in 1.41
205
+ Enabled: true
206
+ Style/DataInheritance: # new in 1.49
207
+ Enabled: true
208
+ Style/DirEmpty: # new in 1.48
209
+ Enabled: true
210
+ Style/EmptyHeredoc: # new in 1.32
211
+ Enabled: true
212
+ Style/ExactRegexpMatch: # new in 1.51
213
+ Enabled: true
214
+ Style/FileEmpty: # new in 1.48
215
+ Enabled: true
216
+ Style/MagicCommentFormat: # new in 1.35
217
+ Enabled: true
218
+ Style/MapToSet: # new in 1.42
219
+ Enabled: true
220
+ Style/MinMaxComparison: # new in 1.42
221
+ Enabled: true
222
+ Style/OperatorMethodCall: # new in 1.37
223
+ Enabled: true
224
+ Style/RedundantArrayConstructor: # new in 1.52
225
+ Enabled: true
226
+ Style/RedundantConstantBase: # new in 1.40
227
+ Enabled: true
228
+ Style/RedundantDoubleSplatHashBraces: # new in 1.41
229
+ Enabled: true
230
+ Style/RedundantEach: # new in 1.38
231
+ Enabled: true
232
+ Style/RedundantFilterChain: # new in 1.52
233
+ Enabled: true
234
+ Style/RedundantHeredocDelimiterQuotes: # new in 1.45
235
+ Enabled: true
236
+ Style/RedundantLineContinuation: # new in 1.49
237
+ Enabled: true
238
+ Style/RedundantRegexpConstructor: # new in 1.52
239
+ Enabled: true
240
+ Style/RedundantStringEscape: # new in 1.37
241
+ Enabled: true
242
+ Capybara/MatchStyle: # new in 2.17
243
+ Enabled: true
244
+ Capybara/NegationMatcher: # new in 2.14
245
+ Enabled: true
246
+ Capybara/SpecificActions: # new in 2.14
247
+ Enabled: true
248
+ Capybara/SpecificFinders: # new in 2.13
249
+ Enabled: true
250
+ FactoryBot/AssociationStyle: # new in 2.23
251
+ Enabled: true
252
+ FactoryBot/ConsistentParenthesesStyle: # new in 2.14
253
+ Enabled: true
254
+ FactoryBot/FactoryAssociationWithStrategy: # new in 2.23
255
+ Enabled: true
256
+ FactoryBot/FactoryNameStyle: # new in 2.16
257
+ Enabled: true
258
+ FactoryBot/RedundantFactoryOption: # new in 2.23
259
+ Enabled: true
260
+ RSpec/BeEmpty: # new in 2.20
261
+ Enabled: true
262
+ RSpec/ContainExactly: # new in 2.19
263
+ Enabled: true
264
+ RSpec/DuplicatedMetadata: # new in 2.16
265
+ Enabled: true
266
+ RSpec/IndexedLet: # new in 2.20
267
+ Enabled: true
268
+ RSpec/MatchArray: # new in 2.19
269
+ Enabled: true
270
+ RSpec/NoExpectationExample: # new in 2.13
271
+ Enabled: true
272
+ RSpec/PendingWithoutReason: # new in 2.16
273
+ Enabled: true
274
+ RSpec/RedundantAround: # new in 2.19
275
+ Enabled: true
276
+ RSpec/SkipBlockInsideExample: # new in 2.19
277
+ Enabled: true
278
+ RSpec/SortMetadata: # new in 2.14
279
+ Enabled: true
280
+ RSpec/Rails/InferredSpecType: # new in 2.14
281
+ Enabled: true
282
+ RSpec/Rails/MinitestAssertions: # new in 2.17
283
+ Enabled: true
284
+ RSpec/Rails/TravelAround: # new in 2.19
285
+ Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,20 +1,20 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-07-19 17:18:47 UTC using RuboCop version 1.31.2.
3
+ # on 2023-06-20 05:53:05 UTC using RuboCop version 1.52.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 1
10
- # Configuration parameters: Include.
10
+ # Configuration parameters: Severity, Include.
11
11
  # Include: **/*.gemspec
12
12
  Gemspec/RequiredRubyVersion:
13
13
  Exclude:
14
14
  - 'assembly-image.gemspec'
15
15
 
16
16
  # Offense count: 2
17
- # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
17
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
18
18
  Metrics/AbcSize:
19
19
  Max: 20
20
20
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assembly-image (2.1.0)
4
+ assembly-image (2.1.2)
5
5
  activesupport (> 6.1)
6
6
  assembly-objectfile (>= 1.6.4)
7
7
  ruby-vips (>= 2.0)
@@ -9,87 +9,100 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.3.1)
12
+ activesupport (7.0.8)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 1.6, < 2)
15
15
  minitest (>= 5.1)
16
16
  tzinfo (~> 2.0)
17
- assembly-objectfile (2.1.0)
17
+ assembly-objectfile (2.2.0)
18
18
  activesupport (>= 5.2.0)
19
19
  mime-types (> 3)
20
20
  mini_exiftool
21
21
  ast (2.4.2)
22
+ base64 (0.1.1)
22
23
  byebug (11.1.3)
23
24
  coderay (1.1.3)
24
- concurrent-ruby (1.1.10)
25
+ concurrent-ruby (1.2.2)
25
26
  diff-lcs (1.5.0)
26
27
  docile (1.4.0)
27
28
  ffi (1.15.5)
28
- i18n (1.12.0)
29
+ i18n (1.14.1)
29
30
  concurrent-ruby (~> 1.0)
30
- json (2.6.2)
31
+ json (2.6.3)
32
+ language_server-protocol (3.17.0.3)
31
33
  method_source (1.0.0)
32
- mime-types (3.4.1)
34
+ mime-types (3.5.1)
33
35
  mime-types-data (~> 3.2015)
34
- mime-types-data (3.2022.0105)
36
+ mime-types-data (3.2023.0808)
35
37
  mini_exiftool (2.10.2)
36
- minitest (5.16.2)
37
- parallel (1.22.1)
38
- parser (3.1.2.0)
38
+ minitest (5.20.0)
39
+ parallel (1.23.0)
40
+ parser (3.2.2.3)
39
41
  ast (~> 2.4.1)
40
- pry (0.13.1)
42
+ racc
43
+ pry (0.14.2)
41
44
  coderay (~> 1.1)
42
45
  method_source (~> 1.0)
43
- pry-byebug (3.9.0)
46
+ pry-byebug (3.10.1)
44
47
  byebug (~> 11.0)
45
- pry (~> 0.13.0)
48
+ pry (>= 0.13, < 0.15)
49
+ racc (1.7.1)
46
50
  rainbow (3.1.1)
47
51
  rake (13.0.6)
48
- regexp_parser (2.5.0)
49
- rexml (3.2.5)
50
- rspec (3.11.0)
51
- rspec-core (~> 3.11.0)
52
- rspec-expectations (~> 3.11.0)
53
- rspec-mocks (~> 3.11.0)
54
- rspec-core (3.11.0)
55
- rspec-support (~> 3.11.0)
56
- rspec-expectations (3.11.0)
52
+ regexp_parser (2.8.1)
53
+ rexml (3.2.6)
54
+ rspec (3.12.0)
55
+ rspec-core (~> 3.12.0)
56
+ rspec-expectations (~> 3.12.0)
57
+ rspec-mocks (~> 3.12.0)
58
+ rspec-core (3.12.2)
59
+ rspec-support (~> 3.12.0)
60
+ rspec-expectations (3.12.3)
57
61
  diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.11.0)
59
- rspec-mocks (3.11.1)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-mocks (3.12.6)
60
64
  diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.11.0)
62
- rspec-support (3.11.0)
63
- rubocop (1.31.2)
65
+ rspec-support (~> 3.12.0)
66
+ rspec-support (3.12.1)
67
+ rubocop (1.56.3)
68
+ base64 (~> 0.1.1)
64
69
  json (~> 2.3)
70
+ language_server-protocol (>= 3.17.0)
65
71
  parallel (~> 1.10)
66
- parser (>= 3.1.0.0)
72
+ parser (>= 3.2.2.3)
67
73
  rainbow (>= 2.2.2, < 4.0)
68
74
  regexp_parser (>= 1.8, < 3.0)
69
75
  rexml (>= 3.2.5, < 4.0)
70
- rubocop-ast (>= 1.18.0, < 2.0)
76
+ rubocop-ast (>= 1.28.1, < 2.0)
71
77
  ruby-progressbar (~> 1.7)
72
- unicode-display_width (>= 1.4.0, < 3.0)
73
- rubocop-ast (1.19.1)
74
- parser (>= 3.1.1.0)
75
- rubocop-rspec (2.12.1)
76
- rubocop (~> 1.31)
77
- ruby-progressbar (1.11.0)
78
+ unicode-display_width (>= 2.4.0, < 3.0)
79
+ rubocop-ast (1.29.0)
80
+ parser (>= 3.2.1.0)
81
+ rubocop-capybara (2.18.0)
82
+ rubocop (~> 1.41)
83
+ rubocop-factory_bot (2.24.0)
84
+ rubocop (~> 1.33)
85
+ rubocop-rspec (2.24.0)
86
+ rubocop (~> 1.33)
87
+ rubocop-capybara (~> 2.17)
88
+ rubocop-factory_bot (~> 2.22)
89
+ ruby-progressbar (1.13.0)
78
90
  ruby-vips (2.1.4)
79
91
  ffi (~> 1.12)
80
- simplecov (0.21.2)
92
+ simplecov (0.22.0)
81
93
  docile (~> 1.1)
82
94
  simplecov-html (~> 0.11)
83
95
  simplecov_json_formatter (~> 0.1)
84
96
  simplecov-html (0.12.3)
85
97
  simplecov_json_formatter (0.1.4)
86
- tzinfo (2.0.5)
98
+ tzinfo (2.0.6)
87
99
  concurrent-ruby (~> 1.0)
88
- unicode-display_width (2.2.0)
100
+ unicode-display_width (2.4.2)
89
101
 
90
102
  PLATFORMS
91
103
  x86_64-darwin-19
92
104
  x86_64-darwin-21
105
+ x86_64-darwin-22
93
106
  x86_64-linux
94
107
 
95
108
  DEPENDENCIES
@@ -102,4 +115,4 @@ DEPENDENCIES
102
115
  simplecov
103
116
 
104
117
  BUNDLED WITH
105
- 2.3.17
118
+ 2.4.13
@@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'assembly-image'
7
- s.version = '2.1.0'
7
+ s.version = '2.1.2'
8
8
  s.authors = ['Peter Mangiafico', 'Renzo Sanchez-Silva', 'Monty Hindman', 'Tony Calavano']
9
9
  s.email = ['pmangiafico@stanford.edu']
10
10
  s.homepage = ''
@@ -35,7 +35,7 @@ module Assembly
35
35
  @overwrite = overwrite
36
36
  end
37
37
 
38
- attr_reader :image, :output_path, :tmp_folder, :tmp_tiff_path
38
+ attr_reader :image, :output_path, :tmp_folder
39
39
 
40
40
  delegate :vips_image, to: :image
41
41
 
@@ -43,19 +43,14 @@ module Assembly
43
43
  def create
44
44
  create_jp2_checks
45
45
 
46
- # KDUcompress doesn’t support arbitrary image types, so we make a temporary tiff
47
- @tmp_tiff_path = make_tmp_tiff
46
+ Dir.mktmpdir('assembly-image', tmp_folder) do |tmp_tiff_dir|
47
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
48
48
 
49
- jp2_command = jp2_create_command(source_path: tmp_tiff_path, output: output_path)
50
- result = `#{jp2_command}`
51
- unless $CHILD_STATUS.success?
52
- # Clean up any partial result
53
- FileUtils.rm_rf(output_path)
54
- raise "JP2 creation command failed: #{jp2_command} with result #{result}"
49
+ # KDUcompress doesn’t support arbitrary image types, so we make a temporary tiff
50
+ make_tmp_tiff(tmp_tiff_path)
51
+ make_jp2(tmp_tiff_path)
55
52
  end
56
53
 
57
- File.delete(tmp_tiff_path) unless tmp_tiff_path.nil?
58
-
59
54
  # create output response object, which is an Assembly::Image type object
60
55
  Image.new(output_path)
61
56
  end
@@ -94,22 +89,22 @@ module Assembly
94
89
  'Clevels=5' # Number of wavelet decomposition levels, or stages
95
90
  ].freeze
96
91
 
92
+ # rubocop:disable Metrics/AbcSize
93
+ # rubocop:disable Metrics/CyclomaticComplexity
97
94
  def create_jp2_checks
95
+ raise "tmp_folder #{tmp_folder} does not exist" unless File.exist?(tmp_folder)
96
+
98
97
  image.send(:check_for_file)
99
98
  raise 'input file is not a valid image, or is the wrong mimetype' unless image.jp2able?
100
99
 
101
100
  raise SecurityError, "output #{output_path} exists, cannot overwrite" if !overwrite? && File.exist?(output_path)
102
101
  raise SecurityError, 'cannot recreate jp2 over itself' if overwrite? && image.mimetype == 'image/jp2' && output_path == image.path
103
102
  end
103
+ # rubocop:enable Metrics/AbcSize
104
+ # rubocop:enable Metrics/CyclomaticComplexity
104
105
 
105
106
  # We do this because we need to reliably compress the tiff and KDUcompress doesn’t support arbitrary image types
106
- # rubocop:disable Metrics/MethodLength
107
- def make_tmp_tiff
108
- raise "tmp_folder #{tmp_folder} does not exist" unless File.exist?(tmp_folder)
109
-
110
- # make temp tiff filename
111
- tmp_tiff_file = Tempfile.new(['assembly-image', '.tif'], tmp_folder)
112
- result_path = tmp_tiff_file.path
107
+ def make_tmp_tiff(tmp_tiff_path)
113
108
  tmp_tiff_image = if vips_image.interpretation.eql?(:cmyk)
114
109
  vips_image.icc_transform(SRGB_ICC, input_profile: CMYK_ICC)
115
110
  elsif image.has_profile?
@@ -118,10 +113,21 @@ module Assembly
118
113
  vips_image
119
114
  end
120
115
 
121
- tmp_tiff_image.tiffsave(result_path, bigtiff: true) # Use bigtiff so we can support images > 4GB
122
- result_path
116
+ tmp_tiff_image.tiffsave(tmp_tiff_path, bigtiff: true) # Use bigtiff so we can support images > 4GB
117
+
118
+ # For troublshooting JP2 creation problems. See https://github.com/sul-dlss/common-accessioning/issues/1079
119
+ raise "Temp tiff files #{tmp_tiff_path} does not exist" unless File.exist?(tmp_tiff_path)
120
+ end
121
+
122
+ def make_jp2(tmp_tiff_path)
123
+ jp2_command = jp2_create_command(source_path: tmp_tiff_path, output: output_path)
124
+ result = `#{jp2_command}`
125
+ return if $CHILD_STATUS.success?
126
+
127
+ # Clean up any partial result
128
+ FileUtils.rm_rf(output_path)
129
+ raise "JP2 creation command failed: #{jp2_command} with result #{result}"
123
130
  end
124
- # rubocop:enable Metrics/MethodLength
125
131
  end
126
132
  end
127
133
  end
@@ -42,6 +42,8 @@ module Assembly
42
42
  end
43
43
 
44
44
  def vips_image
45
+ # Disable cache. Otherwise, Vips gets confused by files with the same filename.
46
+ Vips.cache_set_max_files(0)
45
47
  # autorot will only affect images that need rotation: https://www.libvips.org/API/current/libvips-conversion.html#vips-autorot
46
48
  @vips_image ||= Vips::Image.new_from_file(path).autorot
47
49
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
+ # rubocop:disable RSpec/ExampleLength
5
6
  RSpec.describe Assembly::Image::Jp2Creator do
6
7
  let(:jp2creator) { described_class.new(assembly_image, output: jp2_output_file) }
7
8
  let(:assembly_image) { Assembly::Image.new(input_path) }
@@ -52,9 +53,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
52
53
  expect(result.path).to eq jp2_output_file
53
54
  expect(result.mimetype).to eq 'image/jp2'
54
55
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
55
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
56
- expect(tmp_tiff_image.srgb?).to be true
57
- expect(tmp_tiff_image.has_profile?).to be false
56
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
57
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
58
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
59
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
60
+ expect(tmp_tiff_image.srgb?).to be true
61
+ expect(tmp_tiff_image.has_profile?).to be false
62
+ end
58
63
  end
59
64
  end
60
65
 
@@ -87,9 +92,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
87
92
  expect(result.path).to eq jp2_output_file
88
93
  expect(result.mimetype).to eq 'image/jp2'
89
94
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
90
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
91
- expect(tmp_tiff_image.srgb?).to be true
92
- expect(tmp_tiff_image.has_profile?).to be false
95
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
96
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
97
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
98
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
99
+ expect(tmp_tiff_image.srgb?).to be true
100
+ expect(tmp_tiff_image.has_profile?).to be false
101
+ end
93
102
  end
94
103
  end
95
104
 
@@ -113,7 +122,7 @@ RSpec.describe Assembly::Image::Jp2Creator do
113
122
  generate_test_image(input_path)
114
123
  end
115
124
 
116
- it 'gets the correct image, creates and cleans up the temporary tiff' do
125
+ it 'gets the correct image, creates the temporary tiff' do
117
126
  expect(File).to exist input_path # test image was generated
118
127
  expect(File).not_to exist jp2_output_file
119
128
 
@@ -121,12 +130,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
121
130
  expect(result.path).to eq jp2_output_file
122
131
  expect(result.mimetype).to eq 'image/jp2'
123
132
  # check height and width on temporary tiff (due to CI libvips not speaking jp2)
124
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
125
- expect(tmp_tiff_image.height).to eq 36
126
- expect(tmp_tiff_image.width).to eq 43
127
-
128
- expect(jp2creator.tmp_tiff_path).not_to be_nil # temporary tiff was created
129
- expect(File).not_to exist jp2creator.tmp_tiff_path # the temporary tiff path is cleaned up
133
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
134
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
135
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
136
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
137
+ expect(tmp_tiff_image.height).to eq 36
138
+ expect(tmp_tiff_image.width).to eq 43
139
+ end
130
140
  end
131
141
  end
132
142
 
@@ -144,9 +154,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
144
154
  expect(result.path).to eq jp2_output_file
145
155
  expect(result.mimetype).to eq 'image/jp2'
146
156
  # check height and width on temporary tiff (due to CI libvips not speaking jp2)
147
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
148
- expect(tmp_tiff_image.height).to eq 36
149
- expect(tmp_tiff_image.width).to eq 43
157
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
158
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
159
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
160
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
161
+ expect(tmp_tiff_image.height).to eq 36
162
+ expect(tmp_tiff_image.width).to eq 43
163
+ end
150
164
  end
151
165
  end
152
166
 
@@ -169,9 +183,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
169
183
 
170
184
  # NOTE: we verify the CMYK has been converted to an SRGB JP2 correctly by using ruby-vips;
171
185
  # we have to verify this on the *temporary tiff because lipvips pkg available for circleci does not speak JP2
172
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
173
- expect(tmp_tiff_image.srgb?).to be true
174
- expect(tmp_tiff_image.has_profile?).to be true
186
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
187
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
188
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
189
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
190
+ expect(tmp_tiff_image.srgb?).to be true
191
+ expect(tmp_tiff_image.has_profile?).to be true
192
+ end
175
193
  end
176
194
  end
177
195
 
@@ -189,9 +207,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
189
207
  expect(result.path).to eq jp2_output_file
190
208
  expect(result.mimetype).to eq 'image/jp2'
191
209
  # check height and width on temporary tiff (due to CI libvips not speaking jp2)
192
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
193
- expect(tmp_tiff_image.height).to eq 36
194
- expect(tmp_tiff_image.width).to eq 43
210
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
211
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
212
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
213
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
214
+ expect(tmp_tiff_image.height).to eq 36
215
+ expect(tmp_tiff_image.width).to eq 43
216
+ end
195
217
  end
196
218
  end
197
219
 
@@ -212,9 +234,13 @@ RSpec.describe Assembly::Image::Jp2Creator do
212
234
  expect(result.mimetype).to eq 'image/jp2'
213
235
 
214
236
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
215
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
216
- expect(tmp_tiff_image.srgb?).to be true
217
- expect(tmp_tiff_image.has_profile?).to be false
237
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
238
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
239
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
240
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
241
+ expect(tmp_tiff_image.srgb?).to be true
242
+ expect(tmp_tiff_image.has_profile?).to be false
243
+ end
218
244
  end
219
245
  end
220
246
 
@@ -237,12 +263,16 @@ RSpec.describe Assembly::Image::Jp2Creator do
237
263
  expect(result.mimetype).to eq 'image/jp2'
238
264
 
239
265
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
240
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
241
- expect(tmp_tiff_image.srgb?).to be false
242
- expect(tmp_tiff_image.has_profile?).to be false
243
- vips_for_tmp_tiff = tmp_tiff_image.vips_image
244
- expect(vips_for_tmp_tiff.bands).to eq 1
245
- expect(vips_for_tmp_tiff.interpretation).to eq :'b-w'
266
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
267
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
268
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
269
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
270
+ expect(tmp_tiff_image.srgb?).to be false
271
+ expect(tmp_tiff_image.has_profile?).to be false
272
+ vips_for_tmp_tiff = tmp_tiff_image.vips_image
273
+ expect(vips_for_tmp_tiff.bands).to eq 1
274
+ expect(vips_for_tmp_tiff.interpretation).to eq :'b-w'
275
+ end
246
276
  end
247
277
  end
248
278
 
@@ -267,10 +297,14 @@ RSpec.describe Assembly::Image::Jp2Creator do
267
297
  expect(result.mimetype).to eq 'image/jp2'
268
298
 
269
299
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
270
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
271
- expect(tmp_tiff_image.srgb?).to be true
272
- expect(tmp_tiff_image.has_profile?).to be false
273
- expect(tmp_tiff_image.vips_image.bands).to eq 3
300
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
301
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
302
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
303
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
304
+ expect(tmp_tiff_image.srgb?).to be true
305
+ expect(tmp_tiff_image.has_profile?).to be false
306
+ expect(tmp_tiff_image.vips_image.bands).to eq 3
307
+ end
274
308
  end
275
309
  end
276
310
 
@@ -294,12 +328,16 @@ RSpec.describe Assembly::Image::Jp2Creator do
294
328
  expect(result.mimetype).to eq 'image/jp2'
295
329
 
296
330
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
297
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
298
- expect(tmp_tiff_image.srgb?).to be false
299
- expect(tmp_tiff_image.has_profile?).to be false
300
- vips_for_tmp_tiff = tmp_tiff_image.vips_image
301
- expect(vips_for_tmp_tiff.bands).to eq 1
302
- expect(vips_for_tmp_tiff.interpretation).to eq :'b-w'
331
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
332
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
333
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
334
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
335
+ expect(tmp_tiff_image.srgb?).to be false
336
+ expect(tmp_tiff_image.has_profile?).to be false
337
+ vips_for_tmp_tiff = tmp_tiff_image.vips_image
338
+ expect(vips_for_tmp_tiff.bands).to eq 1
339
+ expect(vips_for_tmp_tiff.interpretation).to eq :'b-w'
340
+ end
303
341
  end
304
342
  end
305
343
 
@@ -321,27 +359,33 @@ RSpec.describe Assembly::Image::Jp2Creator do
321
359
  expect(result.mimetype).to eq 'image/jp2'
322
360
 
323
361
  # check srgb on temporary tiff (due to CI libvips not speaking jp2)
324
- tmp_tiff_image = Assembly::Image.new(jp2creator.send(:make_tmp_tiff))
325
- expect(tmp_tiff_image.srgb?).to be true
326
- expect(tmp_tiff_image.has_profile?).to be false
327
- vips_for_tmp_tiff = tmp_tiff_image.vips_image
328
- expect(vips_for_tmp_tiff.bands).to eq 3
362
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
363
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
364
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
365
+ tmp_tiff_image = Assembly::Image.new(tmp_tiff_path)
366
+ expect(tmp_tiff_image.srgb?).to be true
367
+ expect(tmp_tiff_image.has_profile?).to be false
368
+ vips_for_tmp_tiff = tmp_tiff_image.vips_image
369
+ expect(vips_for_tmp_tiff.bands).to eq 3
370
+ end
329
371
  end
330
372
  end
331
373
  end
332
374
 
333
375
  describe '#make_tmp_tiff' do
334
- subject(:tiff_file) { jp2creator.send(:make_tmp_tiff) }
335
-
336
376
  let(:input_path) { 'spec/test_data/color_rgb_srgb_rot90cw.tif' }
337
- let(:vips_output) { Vips::Image.new_from_file(tiff_file) }
338
377
  let(:plum) { [94.0, 58.0, 101.0] }
339
378
 
340
379
  context 'when given a tiff with a rotation hint' do
341
380
  it 'rotates it' do
342
381
  expect(Vips::Image.new_from_file(input_path).getpoint(3, 3)).not_to eq plum
343
- expect(vips_output.getpoint(3, 3)).to eq plum
382
+ Dir.mktmpdir('assembly-image-test') do |tmp_tiff_dir|
383
+ tmp_tiff_path = File.join(tmp_tiff_dir, 'temp.tif')
384
+ jp2creator.send(:make_tmp_tiff, tmp_tiff_path)
385
+ expect(Vips::Image.new_from_file(tmp_tiff_path).getpoint(3, 3)).to eq plum
386
+ end
344
387
  end
345
388
  end
346
389
  end
347
390
  end
391
+ # rubocop:enable RSpec/ExampleLength
data/spec/spec_helper.rb CHANGED
@@ -169,10 +169,10 @@ def generate_test_image(file, params = {})
169
169
 
170
170
  temp_array = color_gauge_values(cg_type)
171
171
  temp_image = Vips::Image.black(width, height, bands: temp_array.first.size)
172
- (0..4).each do |i|
172
+ 5.times do |i|
173
173
  b = (box_size * i) + (line_size * (i + 1))
174
174
  # d = b + box_size - line_size
175
- (0...6).each do |j|
175
+ 6.times do |j|
176
176
  a = (box_size * j) + (line_size * (j + 1))
177
177
  # c = a + box_size - line_size
178
178
  colors = temp_array.shift
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assembly-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2022-07-19 00:00:00.000000000 Z
14
+ date: 2023-09-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  requirements: []
197
- rubygems_version: 3.2.32
197
+ rubygems_version: 3.3.7
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Ruby immplementation of image services needed to prepare objects to be accessioned