riiif 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -8
- data/app/models/riiif/image.rb +7 -3
- data/lib/riiif/version.rb +1 -1
- data/spec/models/image_spec.rb +18 -5
- data/spec/spec_helper.rb +3 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 201037b36eb8a0a7b31f6953ecaf4dbc980df9d4
|
4
|
+
data.tar.gz: 0eee522bedbd6e2653ef13621267dd23aeeacea0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0789760ccc3002354ad44cd5ca29547417d6375085dc7bb27600852b88df2aed746fbcd1e436f6b74958d09a722575e9deb8afea39f36542c7ffef802b970c38
|
7
|
+
data.tar.gz: dd653f25e076dc6ac8a3207132fd2652cf389158a74b2d6617e3c300ec1478f951c85f787752f9e93a29eb7dc718486129d42876118b8b73616f272f1b2b0e6e
|
data/README.md
CHANGED
@@ -5,6 +5,18 @@ A Ruby IIIF image server as a rails engine
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
+
RIIIF depends on Imagemagick so you must install that first. On a mac using Homebrew you can follow these instructions:
|
9
|
+
|
10
|
+
ImageMagick (6.8.8) may be installed with a few options:
|
11
|
+
* `--with-ghostscript` Compile with Ghostscript for Postscript/PDF support
|
12
|
+
* `--with-tiff` Compile with libtiff support for TIFF files
|
13
|
+
* `--with-jp2` Compile with openjpeg2 support for jpeg2000
|
14
|
+
|
15
|
+
```bash
|
16
|
+
brew install imagemagick --with-ghostscript --with-tiff --with-jp2
|
17
|
+
```
|
18
|
+
|
19
|
+
## Install the gem
|
8
20
|
Add this line to your application's Gemfile:
|
9
21
|
|
10
22
|
gem 'riiif'
|
@@ -63,6 +75,14 @@ Then you can make requests like this:
|
|
63
75
|
* http://www.example.org/image-service/abcd1234/full/150,75/0/native.jpg
|
64
76
|
* http://www.example.org/image-service/abcd1234/full/!150,75/0/native.jpg
|
65
77
|
|
78
|
+
### Route helpers
|
79
|
+
|
80
|
+
It is prefereable that you use the provided route helpers to build these URIs. Here's an example:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
image_tag(Riiif::Engine.routes.url_helpers.image_path(file_id, size: ',600'))
|
84
|
+
```
|
85
|
+
|
66
86
|
### Using a default image
|
67
87
|
|
68
88
|
If there is a request for an id that doesn't exist, a 404 will be returned. You can optionally return an image with this 404 by setting this in your initializer:
|
@@ -77,20 +97,56 @@ You can do this to create a default Riiif::Image to use (useful for passing "mis
|
|
77
97
|
Riiif::Image.new('no_image', Riiif::File.new(Riiif.not_found_image))
|
78
98
|
```
|
79
99
|
|
100
|
+
## Integration with Hydra/Fedora
|
101
|
+
|
102
|
+
Create an initializer like this in `config/initializers/riiif_initializer.rb`
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
# Tell RIIIF to get files via HTTP (not from the local disk)
|
106
|
+
Riiif::Image.file_resolver = Riiif::HTTPFileResolver
|
107
|
+
|
108
|
+
# This tells RIIIF how to resolve the identifier to a URI in Fedora
|
109
|
+
DATASTREAM = 'imageContent'
|
110
|
+
Riiif::HTTPFileResolver.id_to_uri = lambda do |id|
|
111
|
+
connection = ActiveFedora::Base.connection_for_pid(id)
|
112
|
+
host = connection.config[:url]
|
113
|
+
path = connection.api.datastream_content_url(id, DATASTREAM, {})
|
114
|
+
host + '/' + path
|
115
|
+
end
|
116
|
+
|
117
|
+
# In order to return the info.json endpoint, we have to have the full height and width of
|
118
|
+
# each image. If you are using hydra-file_characterization, you have the height & width
|
119
|
+
# cached in Solr. The following block directs the info_service to return those values:
|
120
|
+
HEIGHT_SOLR_FIELD = 'height_isi'
|
121
|
+
WIDTH_SOLR_FIELD = 'width_isi'
|
122
|
+
Riiif::Image.info_service = lambda do |id, file|
|
123
|
+
resp = get_solr_response_for_doc_id id
|
124
|
+
doc = resp.first['response']['docs'].first
|
125
|
+
{ height: doc[HEIGHT_SOLR_FIELD], width: doc[WIDTH_SOLR_FIELD] }
|
126
|
+
end
|
127
|
+
|
128
|
+
include Blacklight::SolrHelper
|
129
|
+
def blacklight_config
|
130
|
+
CatalogController.blacklight_config
|
131
|
+
end
|
132
|
+
|
133
|
+
### ActiveSupport::Benchmarkable (used in Blacklight::SolrHelper) depends on a logger method
|
134
|
+
|
135
|
+
def logger
|
136
|
+
Rails.logger
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
Riiif::Engine.config.cache_duration_in_days = 30
|
141
|
+
```
|
142
|
+
|
143
|
+
|
80
144
|
## Running the tests
|
81
145
|
First, build the engine
|
82
146
|
```bash
|
83
147
|
rake engine_cart:generate
|
84
148
|
```
|
85
149
|
|
86
|
-
ImageMagick must be installed with jasper support
|
87
|
-
```bash
|
88
|
-
brew install imagemagick --with-jasper # if using Homebrew
|
89
|
-
```
|
90
|
-
It appears that as of imagemagick 6.8.8 you have to use openjpeg2 instead of jasper:
|
91
|
-
http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=25357#p109912
|
92
|
-
This doesn't appear to be possible on homebrew until this ticket gets closed: https://github.com/Homebrew/homebrew/issues/28153
|
93
|
-
|
94
150
|
Run the tests
|
95
151
|
```bash
|
96
152
|
rake spec
|
data/app/models/riiif/image.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
module Riiif
|
3
3
|
class Image
|
4
|
-
|
4
|
+
|
5
5
|
class_attribute :file_resolver, :info_service
|
6
6
|
self.file_resolver = FileSystemFileResolver
|
7
7
|
|
@@ -18,13 +18,17 @@ module Riiif
|
|
18
18
|
|
19
19
|
OUTPUT_FORMATS = %W{jpg png}
|
20
20
|
|
21
|
-
attr_reader :id
|
21
|
+
attr_reader :id
|
22
22
|
|
23
23
|
# @param [String] id The identifier of the file to be looked up.
|
24
24
|
# @param [Riiif::File] file Optional: The Riiif::File to use instead of looking one up.
|
25
25
|
def initialize(id, file=nil)
|
26
26
|
@id = id
|
27
|
-
@image = file
|
27
|
+
@image = file if file.present?
|
28
|
+
end
|
29
|
+
|
30
|
+
def image
|
31
|
+
@image ||= file_resolver.find(id)
|
28
32
|
end
|
29
33
|
|
30
34
|
def render(args)
|
data/lib/riiif/version.rb
CHANGED
data/spec/models/image_spec.rb
CHANGED
@@ -31,19 +31,32 @@ describe Riiif::Image do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
context "using HTTPFileResolver" do
|
35
35
|
before do
|
36
36
|
Riiif::Image.file_resolver = Riiif::HTTPFileResolver
|
37
|
-
Riiif::HTTPFileResolver.id_to_uri = lambda do |id|
|
37
|
+
Riiif::HTTPFileResolver.id_to_uri = lambda do |id|
|
38
38
|
"http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/#{id}.jpg/600px-#{id}.jpg"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
after do
|
42
42
|
Riiif::Image.file_resolver = Riiif::FileSystemFileResolver
|
43
43
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
|
45
|
+
describe "get info" do
|
46
|
+
subject { Riiif::Image.new('Cave_26,_Ajanta') }
|
47
|
+
it "should be easy" do
|
48
|
+
expect(subject.info).to eq height: 390, width:600
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the rendered image is in the cache" do
|
53
|
+
subject { Riiif::Image.new('Cave_26,_Ajanta') }
|
54
|
+
before { allow(Rails.cache).to receive(:fetch).and_return('expected') }
|
55
|
+
|
56
|
+
it "should not fetch the file" do
|
57
|
+
expect(Riiif::Image.file_resolver).not_to receive(:find)
|
58
|
+
expect(subject.render(region: 'full', format: 'png')).to eq 'expected'
|
59
|
+
end
|
47
60
|
end
|
48
61
|
end
|
49
62
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,20 +4,13 @@ ENV["RAILS_ENV"] ||= 'test'
|
|
4
4
|
|
5
5
|
EngineCart.load_application!
|
6
6
|
require 'rspec/rails'
|
7
|
-
require 'rspec/autorun'
|
8
7
|
|
9
8
|
|
10
|
-
|
11
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
12
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
13
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
14
|
-
# loaded once.
|
15
|
-
#
|
16
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
9
|
RSpec.configure do |config|
|
18
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
19
10
|
config.run_all_when_everything_filtered = true
|
20
|
-
|
11
|
+
|
12
|
+
config.infer_spec_type_from_file_location!
|
13
|
+
|
21
14
|
|
22
15
|
# Run specs in random order to surface order dependencies. If you find an
|
23
16
|
# order dependency and want to debug it, you can fix the order by providing
|
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: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|