assembly-image 2.1.4 → 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: 5aa835ae3183f8de14d0e677ded80d0ee5ffd813b2150e9fc4665245964dbab1
4
- data.tar.gz: 639cad1edcc8abf76c26598bfd4949085a2fdea49f1acf5802a5a75f6b887c68
3
+ metadata.gz: 61afd775bdcdf7d49e958964cb581deeaca8755250a9cfe459b7a741037c198a
4
+ data.tar.gz: 8d0aedfe78807e2965ca0376589e097b2df9b5ca9647659a626e1fbbfb6beb87
5
5
  SHA512:
6
- metadata.gz: dcc568cc992f74a80e69b6f6bae2eb56a5611a22e848371ce669634037181aae4f735ca2823e35b64037609a4c3b3f473d556fd3830a4d5a33c13d24b6536a59
7
- data.tar.gz: f6cdae8947215307048dc439ef76308cb12b3523ed4722258c0d156bdee189c10c5fab6aee444ab09aeb3b3bff59a3ee4c00a3b5cf51619293a9a1ac8b214f7e
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.4)
4
+ assembly-image (2.2.0)
5
5
  activesupport (> 6.1)
6
6
  assembly-objectfile (>= 1.6.4)
7
7
  ruby-vips (>= 2.0)
@@ -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.4'
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 = ''
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
@@ -19,6 +19,7 @@ TEST_INPUT_DIR = File.join(Assembly::PATH_TO_IMAGE_GEM, 'spec', 'test_data
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.4
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
@@ -10,7 +10,7 @@ authors:
10
10
  - Tony Calavano
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2026-01-09 00:00:00.000000000 Z
13
+ date: 1980-01-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -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:
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
235
  - !ruby/object:Gem::Version
235
236
  version: '0'
236
237
  requirements: []
237
- rubygems_version: 3.6.2
238
+ rubygems_version: 3.7.2
238
239
  specification_version: 4
239
240
  summary: Ruby implementation of image services needed to prepare objects to be accessioned
240
241
  in SULAIR digital library