assembly-image 2.1.3 → 2.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20363be74017e077bf4a7213ad50605a15a09d1db4c3d13a817a489f9510eaa6
4
- data.tar.gz: 3d02e1a8d0bfec9f0cf9d3b61b400f9dd86fa9c858f5210e82e2a6e481ad08c0
3
+ metadata.gz: 61afd775bdcdf7d49e958964cb581deeaca8755250a9cfe459b7a741037c198a
4
+ data.tar.gz: 8d0aedfe78807e2965ca0376589e097b2df9b5ca9647659a626e1fbbfb6beb87
5
5
  SHA512:
6
- metadata.gz: 20a31ca15cc443ab1b0a8b8a82523595c70de654e01863abf6c893771493ad2d5e920733843d3a8b66b6012ed5843f28399a09cfa4ea738c82cf708cc02368ef
7
- data.tar.gz: eca98c8800b2d4bcd51a0df2c5a626879b3d43aa67ac65dfe6e1a0298e485505f17819e9a8bf9a4048cc6b45afaa4c4b7b3aa36a31d49acc8c0f02e8d3fb91b6
6
+ metadata.gz: 465cc5080873a1f079e029925bdfdcd5dd0609afef304cc53190c790608e2805894e3b8f4554a7eac6ed398decc6af077ec19dbfc945e8301d1f2454e026a982
7
+ data.tar.gz: f4cc63a293fe3f2d80074a697b8618e968d9dc49aa323033e4acf22c4513d92b50e5db5b7d3805c9051f366d007e82f4c14858bcb8b0445c4edf484c17b7298e
data/.rubocop.yml CHANGED
@@ -26,7 +26,7 @@ Naming/FileName:
26
26
  Exclude:
27
27
  - lib/assembly-image.rb
28
28
 
29
- Naming/PredicateName:
29
+ Naming/PredicatePrefix:
30
30
  ForbiddenPrefixes:
31
31
  - is_
32
32
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assembly-image (2.1.3)
4
+ assembly-image (2.2.0)
5
5
  activesupport (> 6.1)
6
6
  assembly-objectfile (>= 1.6.4)
7
7
  ruby-vips (>= 2.0)
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activesupport (8.1.1)
12
+ activesupport (8.1.2)
13
13
  base64
14
14
  bigdecimal
15
15
  concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -22,30 +22,37 @@ GEM
22
22
  securerandom (>= 0.3)
23
23
  tzinfo (~> 2.0, >= 2.0.5)
24
24
  uri (>= 0.13.1)
25
- assembly-objectfile (2.2.0)
25
+ assembly-objectfile (2.2.1)
26
26
  activesupport (>= 5.2.0)
27
27
  mime-types (> 3)
28
28
  mini_exiftool
29
29
  ast (2.4.3)
30
30
  base64 (0.3.0)
31
31
  bigdecimal (4.0.1)
32
- byebug (12.0.0)
33
- coderay (1.1.3)
34
32
  concurrent-ruby (1.3.6)
35
33
  connection_pool (3.0.2)
34
+ date (3.5.1)
35
+ debug (1.11.1)
36
+ irb (~> 1.10)
37
+ reline (>= 0.3.8)
36
38
  diff-lcs (1.6.2)
37
39
  docile (1.4.1)
38
40
  drb (2.2.3)
39
- ffi (1.17.2-arm64-darwin)
40
- ffi (1.17.2-x86_64-darwin)
41
- ffi (1.17.2-x86_64-linux-gnu)
41
+ erb (6.0.1)
42
+ ffi (1.17.3-arm64-darwin)
43
+ ffi (1.17.3-x86_64-darwin)
44
+ ffi (1.17.3-x86_64-linux-gnu)
42
45
  i18n (1.14.8)
43
46
  concurrent-ruby (~> 1.0)
47
+ io-console (0.8.2)
48
+ irb (1.16.0)
49
+ pp (>= 0.6.0)
50
+ rdoc (>= 4.0.0)
51
+ reline (>= 0.4.2)
44
52
  json (2.18.0)
45
53
  language_server-protocol (3.17.0.5)
46
54
  lint_roller (1.1.0)
47
55
  logger (1.7.0)
48
- method_source (1.1.0)
49
56
  mime-types (3.7.0)
50
57
  logger
51
58
  mime-types-data (~> 3.2025, >= 3.2025.0507)
@@ -60,18 +67,24 @@ GEM
60
67
  parser (3.3.10.0)
61
68
  ast (~> 2.4.1)
62
69
  racc
70
+ pp (0.6.3)
71
+ prettyprint
72
+ prettyprint (0.2.0)
63
73
  prism (1.7.0)
64
- pry (0.15.2)
65
- coderay (~> 1.1)
66
- method_source (~> 1.0)
67
- pry-byebug (3.11.0)
68
- byebug (~> 12.0)
69
- pry (>= 0.13, < 0.16)
70
74
  pstore (0.2.0)
75
+ psych (5.3.1)
76
+ date
77
+ stringio
71
78
  racc (1.8.1)
72
79
  rainbow (3.1.1)
73
80
  rake (13.3.1)
81
+ rdoc (7.0.3)
82
+ erb
83
+ psych (>= 4.0.0)
84
+ tsort
74
85
  regexp_parser (2.11.3)
86
+ reline (0.6.3)
87
+ io-console (~> 0.5)
75
88
  rspec (3.13.2)
76
89
  rspec-core (~> 3.13.0)
77
90
  rspec-expectations (~> 3.13.0)
@@ -105,7 +118,7 @@ GEM
105
118
  rubocop-factory_bot (2.28.0)
106
119
  lint_roller (~> 1.1)
107
120
  rubocop (~> 1.72, >= 1.72.1)
108
- rubocop-rspec (3.8.0)
121
+ rubocop-rspec (3.9.0)
109
122
  lint_roller (~> 1.1)
110
123
  rubocop (~> 1.81)
111
124
  rubocop-rspec_rails (2.32.0)
@@ -123,6 +136,8 @@ GEM
123
136
  simplecov_json_formatter (~> 0.1)
124
137
  simplecov-html (0.13.2)
125
138
  simplecov_json_formatter (0.1.4)
139
+ stringio (3.2.0)
140
+ tsort (0.2.0)
126
141
  tzinfo (2.0.6)
127
142
  concurrent-ruby (~> 1.0)
128
143
  unicode-display_width (3.2.0)
@@ -132,6 +147,7 @@ GEM
132
147
 
133
148
  PLATFORMS
134
149
  arm64-darwin-23
150
+ arm64-darwin-24
135
151
  x86_64-darwin-19
136
152
  x86_64-darwin-21
137
153
  x86_64-darwin-22
@@ -139,7 +155,7 @@ PLATFORMS
139
155
 
140
156
  DEPENDENCIES
141
157
  assembly-image!
142
- pry-byebug
158
+ debug
143
159
  rake
144
160
  rspec (~> 3.0)
145
161
  rubocop
@@ -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.3'
7
+ s.version = '2.2.0'
8
8
  s.authors = ['Peter Mangiafico', 'Renzo Sanchez-Silva', 'Monty Hindman', 'Tony Calavano']
9
9
  s.email = ['pmangiafico@stanford.edu']
10
10
  s.homepage = ''
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'assembly-objectfile', '>= 1.6.4'
22
22
  s.add_dependency 'ruby-vips', '>= 2.0'
23
23
 
24
- s.add_development_dependency 'pry-byebug'
24
+ s.add_development_dependency 'debug'
25
25
  s.add_development_dependency 'rake'
26
26
  s.add_development_dependency 'rspec', '~> 3.0'
27
27
  s.add_development_dependency 'rubocop'
data/bin/console CHANGED
@@ -2,8 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rubygems'
5
- require 'irb'
5
+ require 'pry'
6
6
 
7
7
  require File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
8
8
 
9
- IRB.start
9
+ Pry.start
@@ -17,6 +17,26 @@ module Assembly
17
17
  vips_image.width
18
18
  end
19
19
 
20
+ # @return [boolean] true if this image is a multi-page (e.g. a TIFF with multiple pages)
21
+ def multi_page?
22
+ return false unless mimetype == 'image/tiff'
23
+
24
+ vips_image.get('n-pages').to_i > 1
25
+ rescue Vips::Error
26
+ false
27
+ end
28
+
29
+ # Extract and save only the first page from a multi-image TIFF
30
+ # @param [String] output_path path to save the extracted first page
31
+ def extract_first_page(output_path)
32
+ raise "Cannot extract first page from mimetype #{mimetype}" unless mimetype == 'image/tiff'
33
+
34
+ first_page = Vips::Image.new_from_file(path, page: 0).autorot
35
+ first_page.write_to_file(output_path)
36
+
37
+ true
38
+ end
39
+
20
40
  # @return [string] full default jp2 path and filename that will be created from the given image
21
41
  # Example: given original file of '/dir/path_to_file.tif', gives '/dir/path_to_file.jp2'
22
42
  def jp2_filename
@@ -22,4 +22,91 @@ RSpec.describe Assembly::Image do
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ describe '#multi_page?' do
27
+ context 'with a single page TIFF' do
28
+ before { generate_test_image(input_path) }
29
+
30
+ it 'returns false' do
31
+ expect(assembly_image.multi_page?).to be false
32
+ end
33
+ end
34
+
35
+ context 'with a multi-page TIFF' do
36
+ let(:input_path) { TEST_MULTIPAGE_TIF_FILE } # this image exists and is in our checked in codebase
37
+
38
+ it 'returns true' do
39
+ expect(assembly_image.multi_page?).to be true
40
+ end
41
+ end
42
+
43
+ context 'with a non-TIFF image' do
44
+ before { generate_test_image(input_path) }
45
+
46
+ let(:input_path) { TEST_JPEG_INPUT_FILE }
47
+
48
+ it 'returns false (JPEG cannot have multiple pages)' do
49
+ expect(assembly_image.multi_page?).to be false
50
+ end
51
+ end
52
+
53
+ context 'when Vips raises an error' do
54
+ before { generate_test_image(input_path) }
55
+
56
+ let(:input_path) { TEST_TIF_INPUT_FILE }
57
+
58
+ it 'rescues the error and returns false' do
59
+ allow(assembly_image.vips_image).to receive(:get).and_raise(Vips::Error, 'Test error')
60
+ expect(assembly_image.multi_page?).to be false
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#extract_first_page' do
66
+ let(:output_path) { File.join(TEST_OUTPUT_DIR, 'extracted.tif') }
67
+
68
+ after { FileUtils.rm_f(output_path) }
69
+
70
+ context 'with a single page TIFF' do
71
+ let(:input_path) { TEST_TIF_INPUT_FILE }
72
+
73
+ before { generate_test_image(input_path) }
74
+
75
+ it 'extracts and saves the first page' do
76
+ expect(assembly_image.multi_page?).to be false
77
+ result = assembly_image.extract_first_page(output_path)
78
+ expect(result).to be true
79
+ expect(File.exist?(output_path)).to be true
80
+ extracted = described_class.new(output_path)
81
+ expect(extracted.width).to eq assembly_image.width
82
+ expect(extracted.height).to eq assembly_image.height
83
+ expect(extracted.multi_page?).to be false
84
+ end
85
+ end
86
+
87
+ context 'with a multi-page TIFF' do
88
+ let(:input_path) { TEST_MULTIPAGE_TIF_FILE } # this is a test multi-page image that exists and is in our checked in codebase
89
+
90
+ it 'extracts only the first page' do
91
+ expect(assembly_image.multi_page?).to be true
92
+ result = assembly_image.extract_first_page(output_path)
93
+ expect(result).to be true
94
+ expect(File.exist?(output_path)).to be true
95
+ extracted = described_class.new(output_path)
96
+ expect(extracted.width).to eq assembly_image.width
97
+ expect(extracted.height).to eq assembly_image.height
98
+ expect(extracted.multi_page?).to be false
99
+ end
100
+ end
101
+
102
+ context 'with different image formats' do
103
+ before { generate_test_image(input_path) }
104
+
105
+ let(:input_path) { TEST_JPEG_INPUT_FILE }
106
+
107
+ it 'raises an error' do
108
+ expect { assembly_image.extract_first_page(output_path) }.to raise_error(RuntimeError, 'Cannot extract first page from mimetype image/jpeg')
109
+ end
110
+ end
111
+ end
25
112
  end
data/spec/spec_helper.rb CHANGED
@@ -13,12 +13,13 @@ end
13
13
 
14
14
  bootfile = File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
15
15
  require bootfile
16
- require 'pry-byebug'
16
+ require 'debug'
17
17
 
18
18
  TEST_INPUT_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data', 'input')
19
19
  TEST_OUTPUT_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data', 'output')
20
20
  TEST_TIF_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.tif')
21
21
  TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
22
+ TEST_MULTIPAGE_TIF_FILE = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data', 'shapes_multi_size.tif')
22
23
 
23
24
  RSpec.configure do |config|
24
25
  # rspec-expectations config goes here. You can use an alternate
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.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
@@ -55,7 +55,7 @@ dependencies:
55
55
  - !ruby/object:Gem::Version
56
56
  version: '2.0'
57
57
  - !ruby/object:Gem::Dependency
58
- name: pry-byebug
58
+ name: debug
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
@@ -216,6 +216,7 @@ files:
216
216
  - spec/test_data/color_rgb_srgb_rot90cw.tif
217
217
  - spec/test_data/input/.empty
218
218
  - spec/test_data/output/.empty
219
+ - spec/test_data/shapes_multi_size.tif
219
220
  homepage: ''
220
221
  licenses: []
221
222
  metadata: