riiif 2.0.0 → 2.1.0

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: b274258986b942fec11fa586bd52f13e9bf8a567725954f8ca6fd92282780207
4
- data.tar.gz: d786222b5b9be2b1c6d514917adb239d498ed819f88f9de93d9a8f61852f1c5a
3
+ metadata.gz: 2e92c056972609b8cb70468fae8b71b34e1974b2ec4caa691af4422187886fa8
4
+ data.tar.gz: eae0755c48ed444ebc292b56f30bd13520d1e34988ec6c7c37087483bbfbd8d8
5
5
  SHA512:
6
- metadata.gz: d4b7a1b45f2513f51abb150a0bc6678bc1578b4ab64da8487b7447af3a0cab2db922d8e7a49a5c737cfd9931e2abcd4f2bbeec37838862ecee49ffaeee6e9eb7
7
- data.tar.gz: 4d06560bdbbf84747e7dba9f341fb6d5eff45dd6e1e573839aa8ec236b42dc242d7a31b8ff9c2bc4d6f31248839c9c3c0e39a76e884569904f7c36aa5aa5834b
6
+ metadata.gz: 5fe8da75c42178b50f8768cdb8f8383043d994865ab917d6b1b74083660b925265f0cd7d08f90f0670e7640c41dcf1b48736926a02855a391c51210ef96256f9
7
+ data.tar.gz: 11dbed920c6e8bd094cbd2ae01e9e5f29de71670833b3d39d231c5ad0415b39fbc4c3da95b9f79dc46d6e6e12f50a962ed4b425ad3d65fa28d960868655db9e1
data/.rubocop.yml CHANGED
@@ -1,3 +1,11 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
  inherit_gem:
3
3
  bixby: bixby_default.yml
4
+
5
+ Bundler/DuplicatedGem:
6
+ Exclude:
7
+ - 'Gemfile'
8
+
9
+ Bundler/OrderedGems:
10
+ Exclude:
11
+ - 'Gemfile'
data/Gemfile CHANGED
@@ -3,3 +3,38 @@ source 'https://rubygems.org'
3
3
  gem 'byebug'
4
4
  # Specify your gem's dependencies in riiif.gemspec
5
5
  gemspec
6
+
7
+ # BEGIN ENGINE_CART BLOCK
8
+ # engine_cart: 2.0.1
9
+ # engine_cart stanza: 0.10.0
10
+ # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
11
+ file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
12
+ if File.exist?(file)
13
+ begin
14
+ eval_gemfile file
15
+ rescue Bundler::GemfileError => e
16
+ Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
17
+ Bundler.ui.warn e.message
18
+ end
19
+ else
20
+ Bundler.ui.warn "[EngineCart] Unable to find test application dependencies in #{file}, using placeholder dependencies"
21
+
22
+ if ENV['RAILS_VERSION']
23
+ if ENV['RAILS_VERSION'] == 'edge'
24
+ gem 'rails', github: 'rails/rails'
25
+ ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
26
+ else
27
+ gem 'rails', ENV['RAILS_VERSION']
28
+ end
29
+ end
30
+
31
+ case ENV['RAILS_VERSION']
32
+ when /^4.2/
33
+ gem 'responders', '~> 2.0'
34
+ gem 'sass-rails', '>= 5.0'
35
+ gem 'coffee-rails', '~> 4.1.0'
36
+ when /^4.[01]/
37
+ gem 'sass-rails', '< 5.0'
38
+ end
39
+ end
40
+ # END ENGINE_CART BLOCK
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  [![Gem Version](https://badge.fury.io/rb/riiif.png)](http://badge.fury.io/rb/riiif)
3
3
  [![Coverage Status](https://coveralls.io/repos/github/curationexperts/riiif/badge.svg?branch=master)](https://coveralls.io/github/curationexperts/riiif?branch=master)
4
4
 
5
+
5
6
  A Ruby IIIF image server as a rails engine
6
7
 
7
8
  ## Installation
@@ -54,7 +54,8 @@ module Riiif
54
54
  ImageInformation.new(
55
55
  width: result[:width],
56
56
  height: result[:height],
57
- format: result[:format]
57
+ format: result[:format],
58
+ channels: result[:channels]
58
59
  )
59
60
  end
60
61
  end
@@ -11,12 +11,13 @@ module Riiif
11
11
  @width = args.first[:width]
12
12
  @height = args.first[:height]
13
13
  @format = args.first[:format]
14
+ @channels = args.first[:channels]
14
15
  end
15
16
  end
16
- attr_reader :format, :height, :width
17
+ attr_reader :format, :height, :width, :channels
17
18
 
18
19
  def to_h
19
- { width: width, height: height, format: format }
20
+ { width: width, height: height, format: format, channels: channels }
20
21
  end
21
22
 
22
23
  # Image information is only valid if height and width are present.
@@ -1,5 +1,5 @@
1
1
  module Riiif
2
- # Get height and width information using imagemagick to interrogate the file
2
+ # Get information using imagemagick to interrogate the file
3
3
  class ImageMagickInfoExtractor
4
4
  # perhaps you want to use GraphicsMagick instead, set to "gm identify"
5
5
  class_attribute :external_command
@@ -10,14 +10,15 @@ module Riiif
10
10
  end
11
11
 
12
12
  def extract
13
- height, width, format = Riiif::CommandRunner.execute(
14
- "#{external_command} -format '%h %w %m' #{@path}[0]"
13
+ height, width, format, channels = Riiif::CommandRunner.execute(
14
+ "#{external_command} -format '%h %w %m %[channels]' #{@path}[0]"
15
15
  ).split(' ')
16
16
 
17
17
  {
18
18
  height: Integer(height),
19
19
  width: Integer(width),
20
- format: format
20
+ format: format,
21
+ channels: channels
21
22
  }
22
23
  end
23
24
  end
@@ -27,7 +27,19 @@ module Riiif
27
27
 
28
28
  # @return [String] a command for running imagemagick to produce the requested output
29
29
  def command
30
- [external_command, crop, size, rotation, colorspace, quality, sampling, metadata, input, output].join
30
+ [
31
+ external_command,
32
+ crop,
33
+ size,
34
+ rotation,
35
+ colorspace,
36
+ quality,
37
+ sampling,
38
+ metadata,
39
+ alpha_channel,
40
+ input,
41
+ output
42
+ ].join
31
43
  end
32
44
 
33
45
  def reduction_factor
@@ -44,6 +56,10 @@ module Riiif
44
56
  transformation.format == 'jpg'.freeze
45
57
  end
46
58
 
59
+ def alpha_channel?
60
+ info.channels =~ /rgba/i
61
+ end
62
+
47
63
  def layer_spec
48
64
  '[0]' if info.format =~ /pdf/i
49
65
  end
@@ -52,9 +68,15 @@ module Riiif
52
68
  " #{path}#{layer_spec}"
53
69
  end
54
70
 
71
+ # In cases where the input file has an alpha_channel but the transformation
72
+ # format is 'jpg', change to 'png' as jpeg does not support alpha channels
55
73
  # pipe the output to STDOUT
56
74
  def output
57
- " #{transformation.format}:-"
75
+ if alpha_channel? && jpeg?
76
+ " png:-"
77
+ else
78
+ " #{transformation.format}:-"
79
+ end
58
80
  end
59
81
 
60
82
  def crop
@@ -81,7 +103,15 @@ module Riiif
81
103
  end
82
104
 
83
105
  def sampling
84
- " -sampling-factor #{sampling_factor}" if jpeg?
106
+ " -sampling-factor #{sampling_factor}" if jpeg? && !alpha_channel?
107
+ end
108
+
109
+ def alpha_channel
110
+ if info.format =~ /pdf/i
111
+ ' -alpha remove'
112
+ elsif alpha_channel?
113
+ ' -alpha on'
114
+ end
85
115
  end
86
116
 
87
117
  def colorspace
data/lib/riiif/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Riiif
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
data/riiif.gemspec CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'railties', '>= 4.2', '<6'
22
22
  spec.add_dependency 'deprecation', '>= 1.0.0'
23
23
  spec.add_dependency 'iiif-image-api', '~> 0.1.0'
24
- spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'bundler'
25
25
  spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'engine_cart', '~> 0.8'
26
+ spec.add_development_dependency 'engine_cart', '~> 2.0'
27
27
  spec.add_development_dependency 'rspec-rails'
28
28
  spec.add_development_dependency 'sqlite3'
29
29
  spec.add_development_dependency 'bixby', '~> 1.0.0'
@@ -147,7 +147,7 @@ RSpec.describe Riiif::ImagesController do
147
147
  before do
148
148
  allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image)
149
149
  allow(image).to(
150
- receive(:info).and_return(Riiif::ImageInformation.new(width: 6000, height: 4000, format: 'JPEG'))
150
+ receive(:info).and_return(Riiif::ImageInformation.new(width: 6000, height: 4000, format: 'JPEG', channels: 'rgb'))
151
151
  )
152
152
  end
153
153
 
@@ -159,6 +159,7 @@ RSpec.describe Riiif::ImagesController do
159
159
  'width' => 6000,
160
160
  'height' => 4000,
161
161
  'format' => 'JPEG',
162
+ 'channels' => 'rgb',
162
163
  'profile' => ['http://iiif.io/api/image/2/level1.json', 'formats' => %w(jpg png)],
163
164
  'protocol' => 'http://iiif.io/api/image'
164
165
  expect(response.headers['Link']).to eq '<http://iiif.io/api/image/2/level1.json>;rel="profile"'
@@ -71,7 +71,7 @@ RSpec.describe Riiif::Image do
71
71
  describe '#render' do
72
72
  before do
73
73
  allow(Riiif::CommandRunner).to receive(:execute)
74
- .with("identify -format '%h %w %m' #{filename}[0]").and_return('131 175 JPEG')
74
+ .with("identify -format '%h %w %m %[channels]' #{filename}[0]").and_return('131 175 JPEG')
75
75
  end
76
76
 
77
77
  describe 'region' do
@@ -1,33 +1,79 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Riiif::ImagemagickCommandFactory do
4
- let(:path) { 'foo.tiff' }
5
- let(:info) { double(height: 100, width: 100, format: 'JPEG') }
4
+ let(:tiff) { 'foo.tiff' }
5
+ let(:pdf) { 'faa.pdf' }
6
+ let(:png) { 'laa.png' }
7
+ let(:channels) { 'rgb' }
8
+ let(:info) { double(height: 100, width: 100, format: source, channels: channels) }
6
9
 
7
10
  describe '.command' do
8
- subject { instance.command }
9
- let(:instance) { described_class.new(path, info, transformation) }
10
-
11
11
  let(:transformation) do
12
12
  IIIF::Image::Transformation.new(region: IIIF::Image::Region::Full.new,
13
13
  size: IIIF::Image::Size::Full.new,
14
14
  quality: 'quality',
15
15
  rotation: 15.2,
16
- format: format)
16
+ format: target)
17
17
  end
18
18
 
19
- context "when it's a jpeg" do
20
- let(:format) { 'jpg' }
19
+ context "when the target format is jpeg" do
20
+ subject { described_class.new(tiff, info, transformation).command }
21
+
22
+ let(:source) { 'tif' }
23
+ let(:target) { 'jpg' }
24
+
21
25
  it { is_expected.to match(/-quality 85/) }
22
26
  end
23
27
 
24
- context "when it's a tiff" do
25
- let(:format) { 'tif' }
28
+ context "when the target format is tiff" do
29
+ subject { described_class.new(tiff, info, transformation).command }
30
+
31
+ let(:source) { 'tif' }
32
+ let(:target) { 'tif' }
33
+
26
34
  it { is_expected.not_to match(/-quality/) }
27
35
  end
28
36
 
37
+ context "when the source format is pdf" do
38
+ subject { described_class.new(pdf, info, transformation).command }
39
+ let(:source) { 'pdf' }
40
+ let(:target) { 'jpg' }
41
+
42
+ it { is_expected.to match(/-alpha\ remove/) }
43
+ end
44
+
45
+ context "when the source and target format is png" do
46
+ subject { described_class.new(png, info, transformation).command }
47
+ let(:source) { 'png' }
48
+ let(:target) { 'png' }
49
+
50
+ it { is_expected.to match(/png:-/) }
51
+ end
52
+
53
+ context "when the source format is png, the png has an alpha channel and the target format is png" do
54
+ subject { described_class.new(png, info, transformation).command }
55
+ let(:source) { 'png' }
56
+ let(:target) { 'png' }
57
+ let(:channels) { 'rgba' }
58
+
59
+ it { is_expected.to match(/alpha on/) }
60
+ end
61
+
62
+ context "when the source format is png, the png has an alpha channel and the target format is jpg" do
63
+ subject { described_class.new(png, info, transformation).command }
64
+ let(:source) { 'png' }
65
+ let(:target) { 'jpg' }
66
+ let(:channels) { 'rgba' }
67
+
68
+ it { is_expected.to match(/alpha on/) }
69
+ it { is_expected.to match(/png:-/) }
70
+ end
71
+
29
72
  describe '#external_command' do
30
- let(:format) { 'jpg' }
73
+ subject { described_class.new(tiff, info, transformation).command }
74
+ let(:source) { 'tif' }
75
+ let(:target) { 'jpg' }
76
+
31
77
  around do |example|
32
78
  orig = described_class.external_command
33
79
  described_class.external_command = 'gm convert'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riiif
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2019-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -62,16 +62,16 @@ dependencies:
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '1.3'
67
+ version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - "~>"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '1.3'
74
+ version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0.8'
95
+ version: '2.0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0.8'
102
+ version: '2.0'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rspec-rails
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  requirements: []
236
236
  rubyforge_project:
237
- rubygems_version: 2.7.6
237
+ rubygems_version: 2.7.9
238
238
  signing_key:
239
239
  specification_version: 4
240
240
  summary: A rails engine that support IIIF requests