Simple library for use with the Djatoka JPEG2000 image server. It helps ease creation of the OpenURLs used by Djatoka.
<img src=“https://travis-ci.org/jronallo/djatoka.png” />
Install the Djatoka image server
gem install djatoka
If you wish to use the curb gem instead of Net::HTTP, install it: gem install curb
# Create a resolver object with a URL. resolver = Djatoka::Resolver.new('http://african.lanl.gov/adore-djatoka/resolver') # A known good identifier identifier = 'info:lanl-repo/ds/5aa182c2-c092-4596-af6e-e95d2e263de3' # Ping the server to see if that resource exists. resolver.ping(identifier) # => <Mash identifier="info:lanl-repo/ds/5aa182c2-c092-4596-af6e-e95d2e263de3" status="OK"> resolver.ping('foobar') # => nil # Create a Djatoka::Metadata object and perform the request to the server for metadata. metadata = resolver.metadata(identifier).perform metadata.levels # => "6" metadata.height # => "3372" metadata.width # => "5120" # Create a Djatoka::Region region = resolver.region(identifier) # Set a scale for the region and return the url as a String. region.scale('600').url # => "http://african.lanl.gov/adore-djatoka/resolver?url_ver=Z39.88-2004&svc.scale=600&rft_id=info%3Alanl-repo%2Fds%2F5aa182c2-c092-4596-af6e-e95d2e263de3&svc_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajpeg2000&svc_id=info%3Alanl-repo%2Fsvc%2FgetRegion"
# Set a new scale for the region and chain together other methods to set further query parameters. region.scale(300).format('image/png').region([1250,550,800,800]).rotate(180).level(5).url # => "http://african.lanl.gov/adore-djatoka/resolver?svc.level=5&url_ver=Z39.88-2004&svc.region=1250%2C550%2C800%2C800&svc.scale=300&rft_id=info%3Alanl-repo%2Fds%2F5aa182c2-c092-4596-af6e-e95d2e263de3&svc_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajpeg2000&svc_id=info%3Alanl-repo%2Fsvc%2FgetRegion&svc.format=image%2Fpng&svc.rotate=180"
This has only been tested in Rails 2.3.x
In config/environment.rb
config.gem 'djatoka'
Install the gem
rake gems:install
In you erb template use one of the Djatoka::ViewHelpers :
<%= djatoka_square_image_tag('info:lanl-repo/ds/5aa182c2-c092-4596-af6e-e95d2e263de3', {:scale => 250, :class => 'djatoka_image', :resolver => 'http://african.lanl.gov/adore-djatoka/resolver' }) %>
If you want to use the OpenLayers viewer, run the generator:
script/generate djatoka
Make sure the included javascripts and jQuery are included in the head.
Edit config/initializers/djatoka.rb to the URL for your Djatoka image server resolver. And then restart your Rails server.
Use the following in you erb template:
<%= djatoka_init_openlayers('http://memory.loc.gov/gmd/gmd433/g4330/g4330/np000066.jp2', 'map') %> <div id='map' style="height:500px;width:500px;"></div>
NOTE: Because the OpenLayers viewer uses Ajax, the Djatoka resolver URL must be at the same site (domain and port) as your application. The scripts also expect the resolver to remain at /adore-djatoka/resolver so maintain that path if you proxy Djatoka or dig into the javascript to change the path.
Tested with the following Ruby versions:
-
1.8.7-p249
-
1.8.7-p302
-
1.9.2-p0
This gem can translate parameters from International Image Interoperability Framework (IIIF) requests into Djatoka requests. It follows the same pattern as creating a Djatoka::Region
# Create a resolver object with a URL. resolver = Djatoka::Resolver.new('http://african.lanl.gov/adore-djatoka/resolver') # A known good identifier identifier = 'info:lanl-repo/ds/5aa182c2-c092-4596-af6e-e95d2e263de3' # IIIF Image Request # Create a IiifRequest with the resolver and id iiif_request = Djatoka::IiifRequest.new(resolver, identifier) # Set IIIF parameters and create a Djatoka::Region # Note: All IIIF parameters are required before creating a Djatoka::Region djatoka_region = iiif_request.region('full').size('full').rotation('0').quality('default').format('jpg').djatoka_region # Use the Djatoka::Region as normal djatoka_region.url # IIIF Info Request (Metadata) # (See the 2.0 Info Request spec)}[http://iiif.io/api/image/2.0/#information-request] # First, create a Djatoka::Metadata object and perform the request to the server for metadata. metadata = resolver.metadata(identifier).perform # Create a IIIF Info json response string # Set values to optional fields by passing in a block and calling setters on the yielded Mash json = metadata.to_iiif_json do |opts| opts.tile_width = 512 # tile_* can be string or int opts.tile_height = "512" opts.compliance_level = 1 opts.formats = ["jpg", "png"] opts.qualities = ["default", "gray"] end
There is also a little commandline utility for outputting the OpenURL.
$ djatoka_url --resolver http://african.lanl.gov/adore-djatoka/resolver --rftid info:lanl-repo/ds/5aa182c2-c092-4596-af6e-e95d2e263de3 --scale 300 --square {"region"=>"0,874,421,421", "scale"=>"300", "level"=>"3"} http://african.lanl.gov/adore-djatoka/resolver?svc.level=3&url_ver=Z39.88-2004&svc.region=0%2C874%2C421%2C421&svc.scale=300&rft_id=info%3Alanl-repo%2Fds%2F5aa182c2-c092-4596-af6e-e95d2e263de3&svc_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajpeg2000&svc_id=info%3Alanl-repo%2Fsvc%2FgetRegion $ djatoka_url --resolver http://african.lanl.gov/adore-djatoka/resolver --rftid info:lanl-repo/ds/5aa182c2-c092-4596-af6e-e95d2e263de3 --smallbox --browser chromium-browser $ djatoka_url --help
-
Testing the view helpers.
-
View more examples of images where the dwtLevels differ from the Djatoka levels.
Jason Ronallo, Willy Mene
Copyright © 2010 North Carolina State University. See LICENSE for details.