riiif 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +1 -1
- data/app/controllers/riiif/images_controller.rb +1 -1
- data/app/models/riiif/image.rb +1 -74
- data/app/models/riiif/image_information.rb +0 -2
- data/app/services/riiif/option_decoder.rb +88 -0
- data/lib/riiif/abstract_file_system_resolver.rb +0 -1
- data/lib/riiif/engine.rb +4 -0
- data/lib/riiif/version.rb +1 -1
- data/lib/riiif.rb +1 -0
- data/spec/models/riiif/image_spec.rb +5 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47aafb94ed533ae1769ddcd23095d428079b28df
|
4
|
+
data.tar.gz: 9aaec28c8c55fd8e936b4d192e31bbe66a39f228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b034b617360e62f487907b1395bef2641f130678729461d23410f48106674516d674a08e1d2a9a814d72d64ec2bcccdefa21a5099f8e6baee93bb304b714cd1
|
7
|
+
data.tar.gz: ed2a2ce3187f8c4f8227cdfcded3d177614d07bdeea331a125737180ed56f0fb0fbaa23e881b02d05a845b65b0638844d6fe265e3a31acc628332a346522b272
|
data/.rubocop_todo.yml
CHANGED
@@ -120,7 +120,7 @@ module Riiif
|
|
120
120
|
CONTEXT => CONTEXT_URI,
|
121
121
|
ID => request.original_url.sub('/info.json', ''),
|
122
122
|
PROTOCOL => PROTOCOL_URI,
|
123
|
-
PROFILE => [LEVEL1, 'formats' =>
|
123
|
+
PROFILE => [LEVEL1, 'formats' => OptionDecoder::OUTPUT_FORMATS]
|
124
124
|
}
|
125
125
|
end
|
126
126
|
end
|
data/app/models/riiif/image.rb
CHANGED
@@ -17,7 +17,6 @@ require_dependency 'riiif/size/imagemagick/percent_decoder'
|
|
17
17
|
require_dependency 'riiif/size/imagemagick/width_decoder'
|
18
18
|
|
19
19
|
module Riiif
|
20
|
-
# rubocop:disable Metrics/ClassLength
|
21
20
|
class Image
|
22
21
|
extend Deprecation
|
23
22
|
|
@@ -37,8 +36,6 @@ module Riiif
|
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
OUTPUT_FORMATS = %w(jpg png).freeze
|
41
|
-
|
42
39
|
attr_reader :id
|
43
40
|
|
44
41
|
# @param [String] id The identifier of the file to be looked up.
|
@@ -62,7 +59,7 @@ module Riiif
|
|
62
59
|
key = Image.cache_key(id, cache_opts)
|
63
60
|
|
64
61
|
cache.fetch(key, compress: true, expires_in: Image.expires_in) do
|
65
|
-
file.extract(
|
62
|
+
file.extract(OptionDecoder.decode(args, info))
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
@@ -89,75 +86,5 @@ module Riiif
|
|
89
86
|
'riiif:' + Digest::MD5.hexdigest(str)
|
90
87
|
end
|
91
88
|
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
##
|
96
|
-
# @param [ActiveSupport::HashWithIndifferentAccess] options
|
97
|
-
# @return [Transformation]
|
98
|
-
def decode_options!(options)
|
99
|
-
raise ArgumentError, "You must provide a format. You provided #{options}" unless options[:format]
|
100
|
-
validate_format!(options[:format])
|
101
|
-
Riiif::Transformation.new(decode_region(options.delete(:region)),
|
102
|
-
decode_size(options.delete(:size)),
|
103
|
-
decode_quality(options[:quality]),
|
104
|
-
decode_rotation(options[:rotation]),
|
105
|
-
options[:format])
|
106
|
-
end
|
107
|
-
|
108
|
-
def decode_quality(quality)
|
109
|
-
return if quality.nil? || %w(default color).include?(quality)
|
110
|
-
return quality if %w(bitonal grey).include?(quality)
|
111
|
-
raise InvalidAttributeError, "Unsupported quality: #{quality}"
|
112
|
-
end
|
113
|
-
|
114
|
-
def decode_rotation(rotation)
|
115
|
-
return if rotation.nil? || rotation == '0'
|
116
|
-
begin
|
117
|
-
Float(rotation)
|
118
|
-
rescue ArgumentError
|
119
|
-
raise InvalidAttributeError, "Unsupported rotation: #{rotation}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def validate_format!(format)
|
124
|
-
raise InvalidAttributeError, "Unsupported format: #{format}" unless OUTPUT_FORMATS.include?(format)
|
125
|
-
end
|
126
|
-
|
127
|
-
def decode_region(region)
|
128
|
-
if region.nil? || region == 'full'
|
129
|
-
Riiif::Region::Imagemagick::FullDecoder.new.decode
|
130
|
-
elsif md = /^pct:(\d+),(\d+),(\d+),(\d+)$/.match(region)
|
131
|
-
Riiif::Region::Imagemagick::PercentageDecoder
|
132
|
-
.new(info, md[1], md[2], md[3], md[4]).decode
|
133
|
-
elsif md = /^(\d+),(\d+),(\d+),(\d+)$/.match(region)
|
134
|
-
Riiif::Region::Imagemagick::AbsoluteDecoder.new(md[1], md[2], md[3], md[4]).decode
|
135
|
-
elsif region == 'square'
|
136
|
-
Riiif::Region::Imagemagick::SquareDecoder.new(info).decode
|
137
|
-
else
|
138
|
-
raise InvalidAttributeError, "Invalid region: #{region}"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
143
|
-
def decode_size(size)
|
144
|
-
if size.nil? || size == 'full'
|
145
|
-
Riiif::Size::Imagemagick::FullDecoder.new.decode
|
146
|
-
elsif md = /^,(\d+)$/.match(size)
|
147
|
-
Riiif::Size::Imagemagick::HeightDecoder.new(md[1]).decode
|
148
|
-
elsif md = /^(\d+),$/.match(size)
|
149
|
-
Riiif::Size::Imagemagick::WidthDecoder.new(md[1]).decode
|
150
|
-
elsif md = /^pct:(\d+(.\d+)?)$/.match(size)
|
151
|
-
Riiif::Size::Imagemagick::PercentDecoder.new(md[1]).decode
|
152
|
-
elsif md = /^(\d+),(\d+)$/.match(size)
|
153
|
-
Riiif::Size::Imagemagick::AbsoluteDecoder.new(md[1], md[2]).decode
|
154
|
-
elsif md = /^!(\d+),(\d+)$/.match(size)
|
155
|
-
Riiif::Size::Imagemagick::BestFitDecoder.new(md[1], md[2]).decode
|
156
|
-
else
|
157
|
-
raise InvalidAttributeError, "Invalid size: #{size}"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
161
89
|
end
|
162
|
-
# rubocop:enable Metrics/ClassLength
|
163
90
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Riiif
|
2
|
+
# Decodes the URL parameters into a Transformation object
|
3
|
+
class OptionDecoder
|
4
|
+
OUTPUT_FORMATS = %w(jpg png).freeze
|
5
|
+
|
6
|
+
# a helper method for instantiating the OptionDecoder
|
7
|
+
# @param [ActiveSupport::HashWithIndifferentAccess] options
|
8
|
+
# @param [ImageInformation] image_info
|
9
|
+
def self.decode(options, image_info)
|
10
|
+
new(options, image_info).decode
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [ActiveSupport::HashWithIndifferentAccess] options
|
14
|
+
# @param [ImageInformation] image_info
|
15
|
+
def initialize(options, image_info)
|
16
|
+
@options = options
|
17
|
+
@image_info = image_info
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :image_info
|
21
|
+
|
22
|
+
##
|
23
|
+
# @return [Transformation]
|
24
|
+
def decode
|
25
|
+
raise ArgumentError, "You must provide a format. You provided #{@options}" unless @options[:format]
|
26
|
+
validate_format!(@options[:format])
|
27
|
+
Riiif::Transformation.new(decode_region(@options.delete(:region)),
|
28
|
+
decode_size(@options.delete(:size)),
|
29
|
+
decode_quality(@options[:quality]),
|
30
|
+
decode_rotation(@options[:rotation]),
|
31
|
+
@options[:format])
|
32
|
+
end
|
33
|
+
|
34
|
+
def decode_quality(quality)
|
35
|
+
return if quality.nil? || %w(default color).include?(quality)
|
36
|
+
return quality if %w(bitonal grey).include?(quality)
|
37
|
+
raise InvalidAttributeError, "Unsupported quality: #{quality}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def decode_rotation(rotation)
|
41
|
+
return if rotation.nil? || rotation == '0'
|
42
|
+
begin
|
43
|
+
Float(rotation)
|
44
|
+
rescue ArgumentError
|
45
|
+
raise InvalidAttributeError, "Unsupported rotation: #{rotation}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_format!(format)
|
50
|
+
raise InvalidAttributeError, "Unsupported format: #{format}" unless OUTPUT_FORMATS.include?(format)
|
51
|
+
end
|
52
|
+
|
53
|
+
def decode_region(region)
|
54
|
+
if region.nil? || region == 'full'
|
55
|
+
Riiif::Region::Imagemagick::FullDecoder.new.decode
|
56
|
+
elsif md = /^pct:(\d+),(\d+),(\d+),(\d+)$/.match(region)
|
57
|
+
Riiif::Region::Imagemagick::PercentageDecoder
|
58
|
+
.new(image_info, md[1], md[2], md[3], md[4]).decode
|
59
|
+
elsif md = /^(\d+),(\d+),(\d+),(\d+)$/.match(region)
|
60
|
+
Riiif::Region::Imagemagick::AbsoluteDecoder.new(md[1], md[2], md[3], md[4]).decode
|
61
|
+
elsif region == 'square'
|
62
|
+
Riiif::Region::Imagemagick::SquareDecoder.new(image_info).decode
|
63
|
+
else
|
64
|
+
raise InvalidAttributeError, "Invalid region: #{region}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
69
|
+
def decode_size(size)
|
70
|
+
if size.nil? || size == 'full'
|
71
|
+
Riiif::Size::Imagemagick::FullDecoder.new.decode
|
72
|
+
elsif md = /^,(\d+)$/.match(size)
|
73
|
+
Riiif::Size::Imagemagick::HeightDecoder.new(md[1]).decode
|
74
|
+
elsif md = /^(\d+),$/.match(size)
|
75
|
+
Riiif::Size::Imagemagick::WidthDecoder.new(md[1]).decode
|
76
|
+
elsif md = /^pct:(\d+(.\d+)?)$/.match(size)
|
77
|
+
Riiif::Size::Imagemagick::PercentDecoder.new(md[1]).decode
|
78
|
+
elsif md = /^(\d+),(\d+)$/.match(size)
|
79
|
+
Riiif::Size::Imagemagick::AbsoluteDecoder.new(md[1], md[2]).decode
|
80
|
+
elsif md = /^!(\d+),(\d+)$/.match(size)
|
81
|
+
Riiif::Size::Imagemagick::BestFitDecoder.new(md[1], md[2]).decode
|
82
|
+
else
|
83
|
+
raise InvalidAttributeError, "Invalid size: #{size}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
87
|
+
end
|
88
|
+
end
|
data/lib/riiif/engine.rb
CHANGED
data/lib/riiif/version.rb
CHANGED
data/lib/riiif.rb
CHANGED
@@ -72,14 +72,14 @@ RSpec.describe Riiif::Image do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
describe '#render' do
|
75
|
+
before do
|
76
|
+
allow(Riiif::CommandRunner).to receive(:execute)
|
77
|
+
.with("identify -format %hx%w #{filename}[0]").and_return('131x175')
|
78
|
+
end
|
79
|
+
|
75
80
|
describe 'region' do
|
76
81
|
subject(:render) { image.render(region: region, format: 'png') }
|
77
82
|
|
78
|
-
before do
|
79
|
-
allow(Riiif::CommandRunner).to receive(:execute)
|
80
|
-
.with("identify -format %hx%w #{filename}[0]").and_return('131x175')
|
81
|
-
end
|
82
|
-
|
83
83
|
context 'when specifing full size' do
|
84
84
|
let(:region) { 'full' }
|
85
85
|
|
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.7.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-09-
|
11
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- app/services/riiif/command_runner.rb
|
181
181
|
- app/services/riiif/image_magick_info_extractor.rb
|
182
182
|
- app/services/riiif/imagemagick_command_factory.rb
|
183
|
+
- app/services/riiif/option_decoder.rb
|
183
184
|
- app/services/riiif/region/imagemagick/absolute_decoder.rb
|
184
185
|
- app/services/riiif/region/imagemagick/full_decoder.rb
|
185
186
|
- app/services/riiif/region/imagemagick/percentage_decoder.rb
|