riiif 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/riiif/images_controller.rb +2 -2
- data/app/models/riiif/file.rb +7 -15
- data/app/services/riiif/imagemagick_command_factory.rb +52 -0
- data/lib/riiif/version.rb +1 -1
- data/spec/models/riiif/image_spec.rb +1 -1
- data/spec/services/riiif/imagemagick_command_factory_spec.rb +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b8dc5c1ffd5532b680b26ff6958a02261700d3e
|
4
|
+
data.tar.gz: 7719e41b21ee91d52eefe4cd5347fb87db25b47c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 453bd022c4fb48291f987625db7c22d6709a7997bb26d9123da975b6ab7537776d847a7d618369788e3e756e08770a99aa29496126540a75a9ed1516b0666814
|
7
|
+
data.tar.gz: 1b96e14965119ee2454f3a44a144b572643af01a00616eff0e5b76fd1a604b1b58ed6f2185d02c33ba811cd8975baa9c8f68ab9c09c2a4139fe4d8e520810342
|
@@ -23,7 +23,7 @@ module Riiif
|
|
23
23
|
data = image.render(image_request_params)
|
24
24
|
headers['Access-Control-Allow-Origin'] = '*'
|
25
25
|
# Set a Cache-Control header
|
26
|
-
expires_in cache_expires, public:
|
26
|
+
expires_in cache_expires, public: public_cache? if status == :ok
|
27
27
|
send_data data,
|
28
28
|
status: status,
|
29
29
|
type: Mime::Type.lookup_by_extension(params[:format]),
|
@@ -35,7 +35,7 @@ module Riiif
|
|
35
35
|
if authorization_service.can?(:info, image)
|
36
36
|
headers['Access-Control-Allow-Origin'] = '*'
|
37
37
|
# Set a Cache-Control header
|
38
|
-
expires_in cache_expires, public:
|
38
|
+
expires_in cache_expires, public: public_cache?
|
39
39
|
render json: image.info.to_h.merge(server_info), content_type: 'application/ld+json'
|
40
40
|
else
|
41
41
|
render json: { error: 'unauthorized' }, status: :unauthorized
|
data/app/models/riiif/file.rb
CHANGED
@@ -33,21 +33,7 @@ module Riiif
|
|
33
33
|
|
34
34
|
# @param [Transformation] transformation
|
35
35
|
def extract(transformation)
|
36
|
-
command =
|
37
|
-
command << " -crop #{transformation.crop}" if transformation.crop
|
38
|
-
command << " -resize #{transformation.size}" if transformation.size
|
39
|
-
if transformation.rotation
|
40
|
-
command << " -virtual-pixel white +distort srt #{transformation.rotation}"
|
41
|
-
end
|
42
|
-
|
43
|
-
case transformation.quality
|
44
|
-
when 'grey'
|
45
|
-
command << ' -colorspace Gray'
|
46
|
-
when 'bitonal'
|
47
|
-
command << ' -colorspace Gray'
|
48
|
-
command << ' -type Bilevel'
|
49
|
-
end
|
50
|
-
command << " #{path} #{transformation.format}:-"
|
36
|
+
command = command_factory.build(path, transformation)
|
51
37
|
execute(command)
|
52
38
|
end
|
53
39
|
|
@@ -57,5 +43,11 @@ module Riiif
|
|
57
43
|
|
58
44
|
delegate :execute, to: Riiif::CommandRunner
|
59
45
|
private :execute
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def command_factory
|
50
|
+
ImagemagickCommandFactory
|
51
|
+
end
|
60
52
|
end
|
61
53
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Riiif
|
2
|
+
# Builds a command to run a transformation using Imagemagick
|
3
|
+
class ImagemagickCommandFactory
|
4
|
+
# A helper method to instantiate and invoke build
|
5
|
+
# @param [String] path the location of the file
|
6
|
+
# @param [Transformation] transformation
|
7
|
+
# @param [Integer] compression (85) the compression level to use (set 0 for no compression)
|
8
|
+
# @return [String] a command for running imagemagick to produce the requested output
|
9
|
+
def self.build(path, transformation, compression: 85)
|
10
|
+
new(path, transformation, compression: compression).build
|
11
|
+
end
|
12
|
+
|
13
|
+
# A helper method to instantiate and invoke build
|
14
|
+
# @param [String] path the location of the file
|
15
|
+
# @param [Transformation] transformation
|
16
|
+
# @param [Integer] compression the compression level to use (set 0 for no compression)
|
17
|
+
def initialize(path, transformation, compression:)
|
18
|
+
@path = path
|
19
|
+
@transformation = transformation
|
20
|
+
@compression = compression
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :path, :transformation, :compression
|
24
|
+
|
25
|
+
# @return [String] a command for running imagemagick to produce the requested output
|
26
|
+
def build
|
27
|
+
command = 'convert'
|
28
|
+
command << " -crop #{transformation.crop}" if transformation.crop
|
29
|
+
command << " -resize #{transformation.size}" if transformation.size
|
30
|
+
if transformation.rotation
|
31
|
+
command << " -virtual-pixel white +distort srt #{transformation.rotation}"
|
32
|
+
end
|
33
|
+
|
34
|
+
case transformation.quality
|
35
|
+
when 'grey'
|
36
|
+
command << ' -colorspace Gray'
|
37
|
+
when 'bitonal'
|
38
|
+
command << ' -colorspace Gray'
|
39
|
+
command << ' -type Bilevel'
|
40
|
+
end
|
41
|
+
command << " -quality #{compression}" if use_compression?
|
42
|
+
command << " #{path} #{transformation.format}:-"
|
43
|
+
command
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def use_compression?
|
49
|
+
compression > 0 && transformation.format == 'jpg'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/riiif/version.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe Riiif::Image do
|
|
6
6
|
subject { described_class.new('world') }
|
7
7
|
describe 'happy path' do
|
8
8
|
before do
|
9
|
-
expect(subject.image).to receive(:execute).with("convert #{filename} jpg:-").and_return('imagedata')
|
9
|
+
expect(subject.image).to receive(:execute).with("convert -quality 85 #{filename} jpg:-").and_return('imagedata')
|
10
10
|
end
|
11
11
|
it 'renders' do
|
12
12
|
expect(subject.render('size' => 'full', format: 'jpg')).to eq 'imagedata'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Riiif::ImagemagickCommandFactory do
|
4
|
+
let(:path) { 'foo.tiff' }
|
5
|
+
|
6
|
+
describe '.build' do
|
7
|
+
subject { described_class.build(path, transformation) }
|
8
|
+
|
9
|
+
let(:transformation) do
|
10
|
+
Riiif::Transformation.new('region',
|
11
|
+
'size',
|
12
|
+
'quality',
|
13
|
+
'rotation',
|
14
|
+
format)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when it's a jpeg" do
|
18
|
+
let(:format) { 'jpg' }
|
19
|
+
it { is_expected.to match(/-quality 85/) }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when it's a tiff" do
|
23
|
+
let(:format) { 'tif' }
|
24
|
+
it { is_expected.not_to match(/-quality/) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
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: 1.
|
4
|
+
version: 1.3.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: 2017-04-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- app/models/riiif/image.rb
|
151
151
|
- app/services/riiif/command_runner.rb
|
152
152
|
- app/services/riiif/image_magick_info_extractor.rb
|
153
|
+
- app/services/riiif/imagemagick_command_factory.rb
|
153
154
|
- app/services/riiif/region/imagemagick/absolute_decoder.rb
|
154
155
|
- app/services/riiif/region/imagemagick/full_decoder.rb
|
155
156
|
- app/services/riiif/region/imagemagick/percentage_decoder.rb
|
@@ -179,6 +180,7 @@ files:
|
|
179
180
|
- spec/models/riiif/image_spec.rb
|
180
181
|
- spec/routing/redirect_spec.rb
|
181
182
|
- spec/routing/resize_routes_spec.rb
|
183
|
+
- spec/services/riiif/imagemagick_command_factory_spec.rb
|
182
184
|
- spec/spec_helper.rb
|
183
185
|
- spec/test_app_templates/Gemfile.extra
|
184
186
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
@@ -214,6 +216,7 @@ test_files:
|
|
214
216
|
- spec/models/riiif/image_spec.rb
|
215
217
|
- spec/routing/redirect_spec.rb
|
216
218
|
- spec/routing/resize_routes_spec.rb
|
219
|
+
- spec/services/riiif/imagemagick_command_factory_spec.rb
|
217
220
|
- spec/spec_helper.rb
|
218
221
|
- spec/test_app_templates/Gemfile.extra
|
219
222
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|