assembly-image 1.7.2 → 1.7.3

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: f0b63b27dda9ccf5d4c74eb214ac9dfff972bb673093635c9c632ddd25ffab79
4
- data.tar.gz: dee6b84e12ec865880d25a1fc1a6c9e75c18fea2ff1350c480590194bf8e55a1
3
+ metadata.gz: de2f277539baa6ffa387830338c620b57a8af08b43a47663641d5371fe0b2d63
4
+ data.tar.gz: c136a6686eafa49d3d7bf306027c5c47084e7a5bdcba5280616577b71630e9a0
5
5
  SHA512:
6
- metadata.gz: 238d3b962f51abce27d957a067d8b5bbcb8976d01238b379ff4e09fd6c2ece55c9c5b5eb01150c156772438b1df150da0c7f7034260429793034fc006e3ee64c
7
- data.tar.gz: 6c85b10c1951aca3fb67af588eecb19577171596c9e86f353f7f16fa15a8750ad162bc498c598be2fe5902389f7d88059b20436a3ae69a4edd6ba62911b7b651
6
+ metadata.gz: 30e6572883cc77167e8f1ee1592e87e3d96e3ae72af80d778e85fcb6a97a36307881ea9116e0ec2cd1a1356248449132e55dbfdc65c83fc749daa5b514fdbe20
7
+ data.tar.gz: 61cd917ee3658cc6d329d8e5046f0cdd9434bcfec3d607d553e754120d7094256c2e36fab611f348e5faaa00703cb1a44f354c9656ec68cda8da11a9414310e9
data/README.md CHANGED
@@ -50,7 +50,8 @@ perform image operations necessary for accessioning of content.
50
50
  * 1.6.5 fix problem with lack of extension in incoming tif causing a problem when creating jp2
51
51
  * 1.6.7 release to github/rubygems
52
52
  * 1.6.9 update mini_exiftool
53
- * 1.7.1 for jp2, only transcode to tiff if not a tiff
53
+ * 1.7.1 for jp2, only transcode to tiff if not a tiff
54
+ * 1.7.3 for jp2, only transcode to tiff if not an uncompressed tiff
54
55
 
55
56
  ## Notes
56
57
 
@@ -54,6 +54,17 @@ module Assembly
54
54
  exif.imagewidth
55
55
  end
56
56
 
57
+ # Examines the input image to determine if it is compressed.
58
+ #
59
+ # @return [boolean] true if image is compressed, false if not.
60
+ #
61
+ # Example:
62
+ # source_img=Assembly::ObjectFile.new('/input/path_to_file.tif')
63
+ # puts source_img.compressed? # gives true
64
+ def compressed?
65
+ exif.compression != 'Uncompressed'
66
+ end
67
+
57
68
  # Add an exif color profile descriptions to the image.
58
69
  # This is useful if your source TIFFs do not have color profile descriptions in the EXIF data, but you know what it should be.
59
70
  # This will allow the images to pass the validaty check and have JP2s created successfully.
@@ -118,12 +129,13 @@ module Assembly
118
129
  # puts derivative_image.path # '/input/path_to_file.jp2'
119
130
  # rubocop:disable Metrics/AbcSize
120
131
  # rubocop:disable Metrics/MethodLength
132
+ # rubocop:disable Metrics/CyclomaticComplexity:
121
133
  def create_jp2(params = {})
122
134
  output = params[:output] || jp2_filename
123
135
  create_jp2_checks(output: output, overwrite: params[:overwrite])
124
136
 
125
137
  # Using instance variable so that can check in tests.
126
- source_path = if mimetype != 'image/tiff'
138
+ source_path = if create_temp_tiff?
127
139
  @tmp_path = make_tmp_tiff(tmp_folder: params[:tmp_folder])
128
140
  else
129
141
  @path
@@ -143,7 +155,10 @@ module Assembly
143
155
 
144
156
  private
145
157
 
146
- # rubocop:disable Metrics/CyclomaticComplexity
158
+ def create_temp_tiff?
159
+ mimetype != 'image/tiff' || compressed?
160
+ end
161
+
147
162
  def create_jp2_checks(output:, overwrite:)
148
163
  check_for_file
149
164
  raise 'input file is not a valid image, or is the wrong mimetype' unless jp2able?
@@ -5,6 +5,6 @@ module Assembly
5
5
  # Main Image class
6
6
  class Image
7
7
  # Project version number
8
- VERSION = '1.7.2'
8
+ VERSION = '1.7.3'
9
9
  end
10
10
  end
@@ -4,32 +4,32 @@ require 'spec_helper'
4
4
 
5
5
  # rubocop:disable Metrics/BlockLength
6
6
  describe Assembly::Image do
7
- it 'should not run if no input file is passed in' do
7
+ it 'does not run if no input file is passed in' do
8
8
  @ai = Assembly::Image.new('')
9
9
  expect{ @ai.create_jp2 }.to raise_error
10
10
  end
11
11
 
12
- it 'should indicate the default jp2 filename' do
12
+ it 'indicates the default jp2 filename' do
13
13
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
14
14
  expect(@ai.jp2_filename).to eq TEST_TIF_INPUT_FILE.gsub('.tif', '.jp2')
15
15
  end
16
16
 
17
- it 'should indicate the default jp2 filename' do
17
+ it 'indicates the default jp2 filename' do
18
18
  @ai = Assembly::Image.new('/path/to/a/file_with_no_extension')
19
19
  expect(@ai.jp2_filename).to eq '/path/to/a/file_with_no_extension.jp2'
20
20
  end
21
21
 
22
- it 'should indicate the default DPG jp2 filename' do
22
+ it 'indicates the default DPG jp2 filename' do
23
23
  @ai = Assembly::Image.new(TEST_DPG_TIF_INPUT_FILE)
24
24
  expect(@ai.dpg_jp2_filename).to eq TEST_DPG_TIF_INPUT_FILE.gsub('.tif', '.jp2').gsub('_00_', '_05_')
25
25
  end
26
26
 
27
- it 'should indicate the default jp2 filename' do
27
+ it 'indicates the default jp2 filename' do
28
28
  @ai = Assembly::Image.new('/path/to/a/file_with_no_00_extension')
29
29
  expect(@ai.dpg_jp2_filename).to eq '/path/to/a/file_with_no_05_extension.jp2'
30
30
  end
31
31
 
32
- it 'should create jp2 when given an RGB tif' do
32
+ it 'creates the jp2 without a temp file when given an uncompressed RGB tif' do
33
33
  generate_test_image(TEST_TIF_INPUT_FILE)
34
34
  expect(File).to exist TEST_TIF_INPUT_FILE
35
35
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
@@ -46,7 +46,24 @@ describe Assembly::Image do
46
46
  expect(@jp2.width).to eq 100
47
47
  end
48
48
 
49
- it 'should create grayscale jp2 when given a bitonal tif' do
49
+ it 'creates the jp2 with a temp file when given a compressed RGB tif' do
50
+ generate_test_image(TEST_TIF_INPUT_FILE, compress: true)
51
+ expect(File).to exist TEST_TIF_INPUT_FILE
52
+ expect(File).to_not exist TEST_JP2_OUTPUT_FILE
53
+ @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
54
+ result = @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE)
55
+ # Indicates a temp tiff was not created.
56
+ expect(@ai.tmp_path).to_not be_nil
57
+ expect(result).to be_a_kind_of Assembly::Image
58
+ expect(result.path).to eq TEST_JP2_OUTPUT_FILE
59
+ expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
60
+ expect(result.exif.colorspace).to eq 'sRGB'
61
+ @jp2 = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
62
+ expect(@jp2.height).to eq 100
63
+ expect(@jp2.width).to eq 100
64
+ end
65
+
66
+ it 'creates grayscale jp2 when given a bitonal tif' do
50
67
  skip 'The latest version of Kakadu may require some changes for this work correctly'
51
68
  # error message is
52
69
  # JP2 creation command failed: kdu_compress -precise -no_weights -quiet Creversible=no Cmodes=BYPASS
@@ -70,7 +87,7 @@ describe Assembly::Image do
70
87
  expect(result.exif.colorspace).to eq 'Grayscale'
71
88
  end
72
89
 
73
- it 'should create color jp2 when given a color tif but bitonal image data (1 channels and 1 bits per pixel)' do
90
+ it 'creates color jp2 when given a color tif but bitonal image data (1 channels and 1 bits per pixel)' do
74
91
  generate_test_image(TEST_TIF_INPUT_FILE, color: 'white', image_type: 'TrueColor', profile: '')
75
92
  expect(File).to exist TEST_TIF_INPUT_FILE
76
93
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
@@ -83,7 +100,7 @@ describe Assembly::Image do
83
100
  expect(result.exif.colorspace).to eq 'sRGB'
84
101
  end
85
102
 
86
- it 'should create grayscale jp2 when given a graycale tif but with bitonal image data (1 channel and 1 bits per pixel)' do
103
+ it 'creates grayscale jp2 when given a graycale tif but with bitonal image data (1 channel and 1 bits per pixel)' do
87
104
  generate_test_image(TEST_TIF_INPUT_FILE, color: 'white', image_type: 'Grayscale', profile: '')
88
105
  expect(File).to exist TEST_TIF_INPUT_FILE
89
106
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
@@ -96,7 +113,7 @@ describe Assembly::Image do
96
113
  expect(result.exif.colorspace).to eq 'Grayscale'
97
114
  end
98
115
 
99
- it 'should create color jp2 when given a color tif but with greyscale image data (1 channel and 8 bits per pixel)' do
116
+ it 'creates color jp2 when given a color tif but with greyscale image data (1 channel and 8 bits per pixel)' do
100
117
  generate_test_image(TEST_TIF_INPUT_FILE, color: 'gray', image_type: 'TrueColor', profile: '')
101
118
  expect(File).to exist TEST_TIF_INPUT_FILE
102
119
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
@@ -109,7 +126,7 @@ describe Assembly::Image do
109
126
  expect(result.exif.colorspace).to eq 'sRGB'
110
127
  end
111
128
 
112
- it 'should create a jp2 when the source image has no profile' do
129
+ it 'creates a jp2 when the source image has no profile' do
113
130
  generate_test_image(TEST_TIF_INPUT_FILE, profile: '') # generate a test input with no profile
114
131
  expect(File).to exist TEST_TIF_INPUT_FILE
115
132
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
@@ -123,7 +140,7 @@ describe Assembly::Image do
123
140
  expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
124
141
  end
125
142
 
126
- it "should not run if the output file exists and you don't allow overwriting" do
143
+ it "does not run if the output file exists and you don't allow overwriting" do
127
144
  generate_test_image(TEST_TIF_INPUT_FILE)
128
145
  generate_test_image(TEST_JP2_OUTPUT_FILE)
129
146
  expect(File).to exist TEST_TIF_INPUT_FILE
@@ -132,14 +149,14 @@ describe Assembly::Image do
132
149
  expect{ @ai.create_jp2(output: TEST_JP2_OUTPUT_FILE) }.to raise_error(SecurityError)
133
150
  end
134
151
 
135
- it 'should get the correct image height and width' do
152
+ it 'gets the correct image height and width' do
136
153
  generate_test_image(TEST_TIF_INPUT_FILE)
137
154
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
138
155
  expect(@ai.height).to eq 100
139
156
  expect(@ai.width).to eq 100
140
157
  end
141
158
 
142
- it 'should not run if the input file is a jp2' do
159
+ it 'does not run if the input file is a jp2' do
143
160
  generate_test_image(TEST_JP2_OUTPUT_FILE)
144
161
  expect(File).to exist TEST_JP2_OUTPUT_FILE
145
162
  @ai = Assembly::Image.new(TEST_JP2_OUTPUT_FILE)
@@ -148,7 +165,7 @@ describe Assembly::Image do
148
165
  expect { @ai.create_jp2 }.to raise_error
149
166
  end
150
167
 
151
- it 'should run if you specify a bogus output profile, because this is not currently an option' do
168
+ it 'runs if you specify a bogus output profile, because this is not currently an option' do
152
169
  generate_test_image(TEST_TIF_INPUT_FILE)
153
170
  expect(File).to exist TEST_TIF_INPUT_FILE
154
171
  @ai = Assembly::Image.new(TEST_TIF_INPUT_FILE)
@@ -159,7 +176,7 @@ describe Assembly::Image do
159
176
  expect(result.exif.colorspace).to eq 'sRGB'
160
177
  end
161
178
 
162
- it 'should create jp2 when given a JPEG' do
179
+ it 'creates jp2 when given a JPEG' do
163
180
  generate_test_image(TEST_JPEG_INPUT_FILE)
164
181
  expect(File).to exist TEST_JPEG_INPUT_FILE
165
182
  expect(File).to_not exist TEST_JP2_OUTPUT_FILE
@@ -173,7 +190,7 @@ describe Assembly::Image do
173
190
  expect(TEST_JP2_OUTPUT_FILE).to be_a_jp2
174
191
  end
175
192
 
176
- it 'should not run if you specify a bogus tmp folder' do
193
+ it 'does not run if you specify a bogus tmp folder' do
177
194
  generate_test_image(TEST_JPEG_INPUT_FILE)
178
195
  bogus_folder = '/crapsticks'
179
196
  expect(File).to exist TEST_JPEG_INPUT_FILE
@@ -182,7 +199,7 @@ describe Assembly::Image do
182
199
  expect { @ai.create_jp2(tmp_folder: bogus_folder) }.to raise_error
183
200
  end
184
201
 
185
- it 'should create a jp2 and preserve the temporary file if specified' do
202
+ it 'creates a jp2 and preserve the temporary file if specified' do
186
203
  generate_test_image(TEST_JPEG_INPUT_FILE)
187
204
  expect(File).to exist TEST_JPEG_INPUT_FILE
188
205
  @ai = Assembly::Image.new(TEST_JPEG_INPUT_FILE)
@@ -196,7 +213,7 @@ describe Assembly::Image do
196
213
  expect(File.exist?(@ai.tmp_path)).to be true
197
214
  end
198
215
 
199
- it 'should create jp2 of the same filename and in the same location as the input if no output file is specified, and should cleanup tmp file' do
216
+ it 'creates a jp2 of the same filename and in the same location as the input if no output file is specified, and should cleanup tmp file' do
200
217
  generate_test_image(TEST_TIF_INPUT_FILE)
201
218
  expect(File).to exist TEST_TIF_INPUT_FILE
202
219
  expect(File.exist?(TEST_JP2_INPUT_FILE)).to be false
@@ -209,7 +226,7 @@ describe Assembly::Image do
209
226
  expect(@ai.tmp_path).to be_nil
210
227
  end
211
228
 
212
- it 'should recreate jp2 if the output file exists and if you allow overwriting' do
229
+ it 'recreates jp2 if the output file exists and if you allow overwriting' do
213
230
  generate_test_image(TEST_TIF_INPUT_FILE)
214
231
  generate_test_image(TEST_JP2_OUTPUT_FILE)
215
232
  expect(File).to exist TEST_TIF_INPUT_FILE
@@ -15,6 +15,8 @@ TEST_DRUID = 'nx288wh8889'
15
15
 
16
16
  # generate a sample image file with a specified profile
17
17
  # rubocop:disable Metrics/AbcSize
18
+ # rubocop:disable Metrics/CyclomaticComplexity
19
+ # rubocop:disable Metrics/MethodLength
18
20
  def generate_test_image(file, params = {})
19
21
  color = params[:color] || 'red'
20
22
  profile = params[:profile] || 'sRGBIEC6196621'
@@ -22,12 +24,15 @@ def generate_test_image(file, params = {})
22
24
  create_command = "convert -size 100x100 xc:#{color} "
23
25
  create_command += ' -profile ' + File.join(Assembly::PATH_TO_IMAGE_GEM, 'profiles', profile + '.icc') + ' ' unless profile == ''
24
26
  create_command += " -type #{image_type} " if image_type
27
+ create_command += ' -compress lzw ' if params[:compress]
25
28
  create_command += file
26
29
  create_command += ' 2>&1'
27
30
  output = `#{ create_command }`
28
31
  raise "Failed to create test image #{file} (#{params}): \n#{output}" unless $CHILD_STATUS.success?
29
32
  end
30
33
  # rubocop:enable Metrics/AbcSize
34
+ # rubocop:enable Metrics/CyclomaticComplexity
35
+ # rubocop:enable Metrics/MethodLength
31
36
 
32
37
  def remove_files(dir)
33
38
  Dir.foreach(dir) do |f|
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: 1.7.2
4
+ version: 1.7.3
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: 2019-03-15 00:00:00.000000000 Z
14
+ date: 2019-04-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: assembly-objectfile
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project: assembly-image
158
- rubygems_version: 2.7.8
158
+ rubygems_version: 2.7.6
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Ruby immplementation of image services needed to prepare objects to be accessioned