assembly-image 2.0.0 → 2.1.1

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: 9379ec53a26a08578c11910512bd73045366fc337fcafb0c7eb1a247370566b1
4
- data.tar.gz: 316fbef312cb027f4061bbe74dc2f8dce993a095d6779da100abeeecbf24b9da
3
+ metadata.gz: 307844d855e2e94047191cbb357f944366345bc9d959b942a26c41ec7f0d6a3c
4
+ data.tar.gz: 966fcaebcf1ef6877da8a9498019b12628f6aa097cfa8b97d22e98fabbba8aac
5
5
  SHA512:
6
- metadata.gz: 97cc720649bdc6e0bb6d7453afdefc7abe3f0931a45976d397f1f77fd2f2dacbcbd4991e64c0e4849a2ae61efa51d72d428ce9a8a15e9a125abdeefcb17b0d5b
7
- data.tar.gz: 8e6580aaade8302319e7cbf41d56d8ac0ebe1a05db5607bed8580cebe8a3c87b5795cb90f50e2b9eb4b081d9048a600799b0e373badf811ff9a084e5f9af3fcc
6
+ metadata.gz: f8c77143ffebd2651796779292d0861aaa9b41f2a7621b8e9991bdc225f297f80d970ef108fdbbd47755b5ac5b65a8f71e64b581042a240d6bc38b19bbf0d2d9
7
+ data.tar.gz: 9870392be2e09567d802d2b5a395feb457e7bbb8d19b1f16a4ce49bcf1cce562f66bab4920c4b5a50d0e5eff41fdae40def644e764d1ee37c3fdee8df30e17bc
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.0.1
3
+ ruby-rails: sul-dlss/ruby-rails@4.1.0
4
4
  workflows:
5
5
  build:
6
6
  jobs:
data/.gitignore CHANGED
@@ -2,7 +2,6 @@
2
2
  *.gem
3
3
  .DS_Store
4
4
  .bundle
5
- Gemfile.lock
6
5
  config/certs/*
7
6
  config/environments/*
8
7
  doc/*
data/.rubocop.yml CHANGED
@@ -22,11 +22,16 @@ Naming/FileName:
22
22
  Exclude:
23
23
  - lib/assembly-image.rb
24
24
 
25
+ Naming/PredicateName:
26
+ ForbiddenPrefixes:
27
+ - is_
28
+
29
+ RSpec/MultipleMemoizedHelpers:
30
+ Enabled: false
31
+
25
32
  Style/WordArray:
26
33
  Enabled: false
27
34
 
28
- Gemspec/DateAssignment: # new in 1.10
29
- Enabled: true
30
35
  Gemspec/RequireMFA: # new in 1.23
31
36
  Enabled: true
32
37
  Layout/LineEndStringConcatenationIndentation: # new in 1.18
@@ -138,10 +143,10 @@ RSpec/IdenticalEqualityAssertion: # new in 2.4
138
143
  Enabled: true
139
144
  RSpec/SubjectDeclaration: # new in 2.5
140
145
  Enabled: true
141
- RSpec/FactoryBot/SyntaxMethods: # new in 2.7
146
+ FactoryBot/SyntaxMethods: # new in 2.7
142
147
  Enabled: true
143
148
  RSpec/Rails/AvoidSetupHook: # new in 2.4
144
- Enabled: true
149
+ Enabled: false
145
150
 
146
151
  Lint/RefinementImportMethods: # new in 1.27
147
152
  Enabled: true
@@ -166,3 +171,115 @@ RSpec/VerifiedDoubleReference: # new in 2.10.0
166
171
 
167
172
  Gemspec/DeprecatedAttributeAssignment: # new in 1.30
168
173
  Enabled: true
174
+ Layout/LineContinuationLeadingSpace: # new in 1.31
175
+ Enabled: true
176
+ Layout/LineContinuationSpacing: # new in 1.31
177
+ Enabled: true
178
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
179
+ Enabled: true
180
+ Lint/NonAtomicFileOperation: # new in 1.31
181
+ Enabled: true
182
+
183
+ Capybara/SpecificMatcher: # new in 2.12
184
+ Enabled: true
185
+ RSpec/Rails/HaveHttpStatus: # new in 2.12
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,78 +1,28 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-06-16 22:15:07 UTC using RuboCop version 1.30.1.
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
- # This cop supports safe autocorrection (--autocorrect).
18
- Lint/RedundantCopDisableDirective:
19
- Exclude:
20
- - 'lib/assembly-image/image.rb'
21
- - 'lib/assembly-image/images.rb'
22
-
23
- # Offense count: 2
24
- # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
17
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
25
18
  Metrics/AbcSize:
26
19
  Max: 20
27
20
 
28
- # Offense count: 14
21
+ # Offense count: 11
29
22
  # Configuration parameters: CountAsOne.
30
23
  RSpec/ExampleLength:
31
- Max: 15
32
-
33
- # Offense count: 2
34
- # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
35
- # Include: **/*_spec*rb*, **/spec/**/*
36
- RSpec/FilePath:
37
- Exclude:
38
- - 'spec/image_spec.rb'
39
- - 'spec/images_spec.rb'
40
-
41
- # Offense count: 21
42
- RSpec/MultipleExpectations:
43
24
  Max: 13
44
25
 
45
- # Offense count: 5
46
- RSpec/UnspecifiedException:
47
- Exclude:
48
- - 'spec/image_spec.rb'
49
- - 'spec/images_spec.rb'
50
-
51
- # Offense count: 3
52
- Style/CombinableLoops:
53
- Exclude:
54
- - 'spec/images_spec.rb'
55
-
56
- # Offense count: 1
57
- # This cop supports unsafe autocorrection (--autocorrect-all).
58
- Style/GlobalStdStream:
59
- Exclude:
60
- - 'lib/assembly-image/images.rb'
61
-
62
- # Offense count: 1
63
- # Configuration parameters: AllowedMethods.
64
- # AllowedMethods: respond_to_missing?
65
- Style/OptionalBooleanParameter:
66
- Exclude:
67
- - 'lib/assembly-image/image.rb'
68
-
69
- # Offense count: 7
70
- # This cop supports unsafe autocorrection (--autocorrect-all).
71
- # Configuration parameters: Mode.
72
- Style/StringConcatenation:
73
- Exclude:
74
- - 'bin/console'
75
- - 'config/boot.rb'
76
- - 'lib/assembly-image.rb'
77
- - 'lib/assembly-image/images.rb'
78
- - 'spec/spec_helper.rb'
26
+ # Offense count: 15
27
+ RSpec/MultipleExpectations:
28
+ Max: 11
data/.rvmrc.example CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3@assembly-image --create
1
+ rvm use 3.1.0@assembly-image --create
data/Gemfile.lock ADDED
@@ -0,0 +1,118 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ assembly-image (2.1.1)
5
+ activesupport (> 6.1)
6
+ assembly-objectfile (>= 1.6.4)
7
+ ruby-vips (>= 2.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activesupport (7.0.8)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ assembly-objectfile (2.2.0)
18
+ activesupport (>= 5.2.0)
19
+ mime-types (> 3)
20
+ mini_exiftool
21
+ ast (2.4.2)
22
+ base64 (0.1.1)
23
+ byebug (11.1.3)
24
+ coderay (1.1.3)
25
+ concurrent-ruby (1.2.2)
26
+ diff-lcs (1.5.0)
27
+ docile (1.4.0)
28
+ ffi (1.15.5)
29
+ i18n (1.14.1)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.6.3)
32
+ language_server-protocol (3.17.0.3)
33
+ method_source (1.0.0)
34
+ mime-types (3.5.1)
35
+ mime-types-data (~> 3.2015)
36
+ mime-types-data (3.2023.0808)
37
+ mini_exiftool (2.10.2)
38
+ minitest (5.20.0)
39
+ parallel (1.23.0)
40
+ parser (3.2.2.3)
41
+ ast (~> 2.4.1)
42
+ racc
43
+ pry (0.14.2)
44
+ coderay (~> 1.1)
45
+ method_source (~> 1.0)
46
+ pry-byebug (3.10.1)
47
+ byebug (~> 11.0)
48
+ pry (>= 0.13, < 0.15)
49
+ racc (1.7.1)
50
+ rainbow (3.1.1)
51
+ rake (13.0.6)
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)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-mocks (3.12.6)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.12.0)
66
+ rspec-support (3.12.1)
67
+ rubocop (1.56.3)
68
+ base64 (~> 0.1.1)
69
+ json (~> 2.3)
70
+ language_server-protocol (>= 3.17.0)
71
+ parallel (~> 1.10)
72
+ parser (>= 3.2.2.3)
73
+ rainbow (>= 2.2.2, < 4.0)
74
+ regexp_parser (>= 1.8, < 3.0)
75
+ rexml (>= 3.2.5, < 4.0)
76
+ rubocop-ast (>= 1.28.1, < 2.0)
77
+ ruby-progressbar (~> 1.7)
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)
90
+ ruby-vips (2.1.4)
91
+ ffi (~> 1.12)
92
+ simplecov (0.22.0)
93
+ docile (~> 1.1)
94
+ simplecov-html (~> 0.11)
95
+ simplecov_json_formatter (~> 0.1)
96
+ simplecov-html (0.12.3)
97
+ simplecov_json_formatter (0.1.4)
98
+ tzinfo (2.0.6)
99
+ concurrent-ruby (~> 1.0)
100
+ unicode-display_width (2.4.2)
101
+
102
+ PLATFORMS
103
+ x86_64-darwin-19
104
+ x86_64-darwin-21
105
+ x86_64-darwin-22
106
+ x86_64-linux
107
+
108
+ DEPENDENCIES
109
+ assembly-image!
110
+ pry-byebug
111
+ rake
112
+ rspec (~> 3.0)
113
+ rubocop
114
+ rubocop-rspec
115
+ simplecov
116
+
117
+ BUNDLED WITH
118
+ 2.4.13
data/README.md CHANGED
@@ -6,24 +6,16 @@
6
6
  # Assembly Image Gem
7
7
 
8
8
  ## Overview
9
- This gem contains classes used by the Stanford University Digital Library to
10
- perform image operations necessary for accessioning of content.
9
+ This gem contains classes used by the Stanford University Digital Library to create JP2 image derivatives.
11
10
 
12
- Requires image processing software - see PreRequisites section below.
11
+ Requires image processing software - see [prerequisites section](#prerequisites) below.
13
12
 
14
13
  ## Notes
15
14
 
16
15
  1. The gem assumes that the user context in which it is executed has write access to the 'tmp' folder.
17
- This is because color profiles can be extracted from images during the JP2
18
- creation process, and these profiles need to be stored as local files, and it
19
- is beneficial to cache them for later usage by images with the same color profile.
20
- If you know there are color profiles which are commonly used, it is better to
21
- capture them in the gem itself in the profile folder so they can be re-used
22
- and do not need to be extracted.
23
- 1. If any errors occur during JP2 generation for any reason, a runtime exception will be thrown with a description of the error.
24
- 2. If an image is passed in with a color profile that cannot be determined by examining the exif header data, an exception will be thrown.
25
-
26
- This can commonly occur in basic test TIFs that are black/white and have no profile, so beware during testing.
16
+ This is to create the temporary tiffs used; we need temporary tiffs to reliably compress the image using KDUcompress, which doesn’t support arbitrary image types
17
+ 2. If any errors occur during JP2 generation for any reason, a runtime exception will be thrown with a description of the error.
18
+ 3. If an image is passed in with a color profile that cannot be determined, an exception will be thrown. This can commonly occur in basic test TIFs that are black/white and have no profile, so beware during testing.
27
19
 
28
20
  ## Usage
29
21
 
@@ -31,45 +23,29 @@ To use the JP2 creation method, you first instantiate the image object with an i
31
23
 
32
24
  ```ruby
33
25
  require 'assembly-image'
34
- input = Assembly::Image.new('/full/path/to/file.tif')
35
- puts input.exif # show exif header information for the TIF
36
- output = input.create_jp2(:output=>'/full/path/to/output.jp2') # generate a new JP2 in the specified location
37
- puts output.exif # show exif header information for the JP2
26
+ input_image = Assembly::Image.new('/full/path/to/file.tif')
27
+ output = input_image.create_jp2(output: '/full/path/to/output.jp2') # generate a new JP2 in the specified location
38
28
  ```
39
29
 
40
30
  ## Running tests
41
31
 
42
32
  ```bash
43
- bundle exec rake
44
- ```
45
-
46
- ## Generate documentation
47
- To generate documentation into the "doc" folder:
48
-
49
- ```bash
50
- yard
51
- ```
52
-
53
- To keep a local server running with up to date code documentation that you can view in your browser:
54
-
55
- ```bash
56
- yard server --reload
33
+ bundle exec rspec
57
34
  ```
58
35
 
59
36
  ## Prerequisites
60
37
 
61
38
  1. Kakadu Proprietary Software Binaries - for JP2 generation
62
- 1. ImageMagick 6.5.4 or higher
63
- 1. Exiftool
39
+ 1. Libvips
40
+ 1. Exiftool - upstream dependency of assembly-objectfile (used by specs to check mimetype of produced jp2, and because there is no libvips package available for circleci that speaks jp2)
64
41
 
65
42
  ### Kakadu
66
43
 
67
44
  Download and install demonstration binaries from Kakadu:
68
45
  http://kakadusoftware.com/downloads/
69
46
 
70
- NOTE: If you have upgrade to El Capitan on OS X, you will need to donwload and re-install the latest version of Kakadu, due to changes made with SIP. These changes moved the old executable binaries to an inaccessible location.
71
-
72
47
  ### Libvips
48
+ Note: libvips may require a significant amount of space for temporary files. The location for this can be controlled by the TMPDIR environment variable.
73
49
 
74
50
  #### Mac
75
51
 
@@ -79,7 +55,7 @@ brew install libvips
79
55
 
80
56
  ### Exiftool
81
57
 
82
- #### RHEL
58
+ #### Linux
83
59
  Download latest version from: http://www.sno.phy.queensu.ca/~phil/exiftool
84
60
 
85
61
  ```bash
@@ -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.0.0'
7
+ s.version = '2.1.1'
8
8
  s.authors = ['Peter Mangiafico', 'Renzo Sanchez-Silva', 'Monty Hindman', 'Tony Calavano']
9
9
  s.email = ['pmangiafico@stanford.edu']
10
10
  s.homepage = ''
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  s.require_paths = ['lib']
19
19
 
20
+ s.add_dependency 'activesupport', '> 6.1'
20
21
  s.add_dependency 'assembly-objectfile', '>= 1.6.4'
21
- s.add_dependency 'mini_exiftool', '>= 1.6', '< 3'
22
22
  s.add_dependency 'ruby-vips', '>= 2.0'
23
23
 
24
24
  s.add_development_dependency 'pry-byebug'
@@ -27,5 +27,4 @@ Gem::Specification.new do |s|
27
27
  s.add_development_dependency 'rubocop'
28
28
  s.add_development_dependency 'rubocop-rspec'
29
29
  s.add_development_dependency 'simplecov'
30
- s.add_development_dependency 'yard'
31
30
  end
data/bin/console CHANGED
@@ -4,6 +4,6 @@
4
4
  require 'rubygems'
5
5
  require 'irb'
6
6
 
7
- require File.expand_path(File.dirname(__FILE__) + '/../config/boot')
7
+ require File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
8
8
 
9
9
  IRB.start
data/config/boot.rb CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'rubygems'
4
4
 
5
- project_root = File.expand_path(File.dirname(__FILE__) + '/..')
5
+ project_root = File.expand_path("#{File.dirname(__FILE__)}/..")
6
6
 
7
7
  # Load config for current environment.
8
- $LOAD_PATH.unshift(project_root + '/lib')
8
+ $LOAD_PATH.unshift("#{project_root}/lib")
9
9
 
10
10
  require 'assembly-image'
@@ -3,6 +3,7 @@
3
3
  require 'assembly-objectfile'
4
4
  require 'tempfile'
5
5
  require 'English' # see https://github.com/rubocop-hq/rubocop/issues/1747 (not #MAGA related)
6
+ require 'active_support/core_ext/module/delegation'
6
7
 
7
8
  module Assembly
8
9
  class Image < Assembly::ObjectFile
@@ -14,47 +15,46 @@ module Assembly
14
15
  # @return [Assembly::Image] object containing the generated JP2 file
15
16
  #
16
17
  # @param [Assembly::Image] the image file
17
- # @param [Hash] params Optional parameters specified as a hash, using symbols for options:
18
- # * :output => path to the output JP2 file (default: mirrors the source file name and path, but with a .jp2 extension)
19
- # * :overwrite => if set to false, an existing JP2 file with the same name won't be overwritten (default: false)
20
- # * :tmp_folder => the temporary folder to use when creating the jp2 (default: '/tmp'); also used by imagemagick
18
+ # @param [String] output path to the output JP2 file (default: mirrors the source file name and path, but with a .jp2 extension)
19
+ # @param [Boolean] overwrite if set to false, an existing JP2 file with the same name won't be overwritten (default: false)
20
+ # @param [Dir] tmp_folder the temporary folder to use when creating the jp2 (default: '/tmp'); also used by imagemagick
21
21
  #
22
22
  # Example:
23
23
  # source_img = Assembly::Image.new('/input/path_to_file.tif')
24
- # derivative_img = source_img.create_jp2(:overwrite=>true)
24
+ # derivative_img = source_img.create_jp2(overwrite: true)
25
25
  # puts derivative_img.mimetype # 'image/jp2'
26
26
  # puts derivative_image.path # '/input/path_to_file.jp2'
27
- def self.create(image, params = {})
28
- new(image, params).create
27
+ def self.create(image, **args)
28
+ new(image, **args).create
29
29
  end
30
30
 
31
- def initialize(image, params)
31
+ def initialize(image, overwrite: false, output: image.jp2_filename, tmp_folder: Dir.tmpdir)
32
32
  @image = image
33
- @output_path = params.fetch(:output, image.jp2_filename)
34
- @tmp_folder = params[:tmp_folder]
35
- @overwrite = params[:overwrite]
36
- @params = params
33
+ @output_path = output
34
+ @tmp_folder = tmp_folder
35
+ @overwrite = overwrite
37
36
  end
38
37
 
39
- attr_reader :image, :output_path, :tmp_folder, :tmp_path
38
+ attr_reader :image, :output_path, :tmp_folder, :tmp_tiff_path
39
+
40
+ delegate :vips_image, to: :image
40
41
 
41
42
  # @return [Assembly::Image] object containing the generated JP2 file
42
43
  def create
43
44
  create_jp2_checks
44
45
 
45
- # Using instance variable so that can check in tests.
46
- # We do this because we need to reliably compress the tiff and KDUcompress doesn’t support arbitrary image types
47
- @tmp_path = make_tmp_tiff(tmp_folder: tmp_folder)
46
+ # KDUcompress doesn’t support arbitrary image types, so we make a temporary tiff
47
+ @tmp_tiff_path = make_tmp_tiff
48
48
 
49
- jp2_command = jp2_create_command(source_path: @tmp_path, output: output_path)
49
+ jp2_command = jp2_create_command(source_path: tmp_tiff_path, output: output_path)
50
50
  result = `#{jp2_command}`
51
51
  unless $CHILD_STATUS.success?
52
52
  # Clean up any partial result
53
- File.delete(output_path) if File.exist?(output_path)
53
+ FileUtils.rm_rf(output_path)
54
54
  raise "JP2 creation command failed: #{jp2_command} with result #{result}"
55
55
  end
56
56
 
57
- File.delete(@tmp_path) unless @tmp_path.nil?
57
+ File.delete(tmp_tiff_path) unless tmp_tiff_path.nil?
58
58
 
59
59
  # create output response object, which is an Assembly::Image type object
60
60
  Image.new(output_path)
@@ -68,8 +68,10 @@ module Assembly
68
68
 
69
69
  def jp2_create_command(source_path:, output:)
70
70
  options = []
71
- # TODO: Consider using ruby-vips to determine the colorspace instead of relying on exif (which is done below)
72
- options << '-jp2_space sRGB' if image.samples_per_pixel == 3
71
+ # CMYK becomes sRGB in make_tmp_tiff, so jp2_space option will be set for sRGB and CMYK
72
+ # TODO: we're not sure at this time what happens for grayscale (or what Tony C. wants for grayscale)
73
+ # see https://github.com/sul-dlss/assembly-image/issues/98
74
+ options << '-jp2_space sRGB' if image.srgb?
73
75
  options += KDU_COMPRESS_DEFAULT_OPTIONS
74
76
  options << "Clayers=#{layers}"
75
77
  "kdu_compress #{options.join(' ')} -i '#{source_path}' -o '#{output}' 2>&1"
@@ -100,32 +102,24 @@ module Assembly
100
102
  raise SecurityError, 'cannot recreate jp2 over itself' if overwrite? && image.mimetype == 'image/jp2' && output_path == image.path
101
103
  end
102
104
 
103
- # Bigtiff needs to be used if size of image exceeds 2^32 bytes.
104
- def need_bigtiff?
105
- image.image_data_size >= 2**32
106
- end
107
-
108
105
  # We do this because we need to reliably compress the tiff and KDUcompress doesn’t support arbitrary image types
109
106
  # rubocop:disable Metrics/MethodLength
110
- def make_tmp_tiff(tmp_folder: nil)
111
- tmp_folder ||= Dir.tmpdir
112
- raise "tmp_folder #{tmp_folder} does not exists" unless File.exist?(tmp_folder)
107
+ def make_tmp_tiff
108
+ raise "tmp_folder #{tmp_folder} does not exist" unless File.exist?(tmp_folder)
113
109
 
114
110
  # make temp tiff filename
115
111
  tmp_tiff_file = Tempfile.new(['assembly-image', '.tif'], tmp_folder)
116
- tmp_path = tmp_tiff_file.path
117
- vips_image = Vips::Image.new_from_file image.path
118
-
119
- vips_image = if vips_image.interpretation.eql?(:cmyk)
120
- vips_image.icc_transform(SRGB_ICC, input_profile: CMYK_ICC)
121
- elsif !image.profile.nil?
122
- vips_image.icc_transform(SRGB_ICC, embedded: true)
123
- else
124
- vips_image
125
- end
126
-
127
- vips_image.tiffsave(tmp_path, bigtiff: need_bigtiff?)
128
- tmp_path
112
+ result_path = tmp_tiff_file.path
113
+ tmp_tiff_image = if vips_image.interpretation.eql?(:cmyk)
114
+ vips_image.icc_transform(SRGB_ICC, input_profile: CMYK_ICC)
115
+ elsif image.has_profile?
116
+ vips_image.icc_transform(SRGB_ICC, embedded: true)
117
+ else
118
+ vips_image
119
+ end
120
+
121
+ tmp_tiff_image.tiffsave(result_path, bigtiff: true) # Use bigtiff so we can support images > 4GB
122
+ result_path
129
123
  end
130
124
  # rubocop:enable Metrics/MethodLength
131
125
  end