Class: IIIF::V3::Presentation::ImageResource
- Inherits:
-
Resource
- Object
- AbstractResource
- Resource
- IIIF::V3::Presentation::ImageResource
- Defined in:
- lib/iiif/v3/presentation/image_resource.rb
Constant Summary collapse
- TYPE =
'Image'.freeze
- IMAGE_API_DEFAULT_PARAMS =
'/full/!200,200/0/default.jpg'.freeze
- DEFAULT_FORMAT =
'image/jpeg'.freeze
Constants inherited from AbstractResource
AbstractResource::CONTENT_RESOURCE_PROPERTIES, AbstractResource::PAGING_PROPERTIES
Constants included from HashBehaviours
HashBehaviours::SIMPLE_SELF_RETURNERS
Class Method Summary collapse
-
.create_image_api_image_resource(params = {}) ⇒ Object
Create a new ImageResource that includes a IIIF Image API Service See http://iiif.io/api/presentation/2.0/#image-resources.
Instance Method Summary collapse
-
#initialize(hsh = {}) ⇒ ImageResource
constructor
A new instance of ImageResource.
Methods inherited from Resource
#prohibited_keys, #required_keys, #uri_only_keys, #validate
Methods inherited from AbstractResource
#any_type_keys, #array_only_keys, from_ordered_hash, #hash_only_keys, #int_only_keys, #legal_viewing_direction_values, #legal_viewing_hint_values, #numeric_only_keys, parse, #prohibited_keys, #required_keys, #string_only_keys, #to_json, #to_ordered_hash, #uri_only_keys, #validate
Methods included from HashBehaviours
#clear, #merge, #merge!, #reject!, #select, #select!
Constructor Details
#initialize(hsh = {}) ⇒ ImageResource
Returns a new instance of ImageResource.
10 11 12 13 |
# File 'lib/iiif/v3/presentation/image_resource.rb', line 10 def initialize(hsh={}) hsh['type'] = TYPE unless hsh.has_key? 'type' super(hsh) end |
Class Method Details
.create_image_api_image_resource(params = {}) ⇒ Object
Create a new ImageResource that includes a IIIF Image API Service See http://iiif.io/api/presentation/2.0/#image-resources
Params
- :service_id (required) - The base URI for the image on the image server.
- :resource_id - The id for the resource; if supplied this should
resolve to an actual image. Default:
"#{:service_id}/full/!200,200/0/default.jpg" - :format - The format of the image that is returned when
:resource_idis resolved. Default: 'image/jpeg' - :height (Integer)
- :profile (String)
- :width (Integer) - If width, height, and profile are not supplied, this method will try to get the info from the server (based on :resource_id) and raise an Exception if this is not possible for some reason.
- :copy_info (bool)- Even if width and height are supplied, try to get the info.json from the server and copy it in. Default: false
Raises:
- KeyError if
:service_idis not supplied - Expections related to HTTP problems if a call to an image server fails
The result is something like this:
{ "id":"http://www.example.org/iiif/book1/res/page1.jpg", "type": "Image", "format": "image/jpeg", "service": { "@context": "http://iiif.io/api/image/2/context.json", "id":"http://www.example.org/images/book1-page1", "profile":"http://iiif.io/api/image/2/profiles/level2.json", }, "height":2000, "width":1500 }
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/iiif/v3/presentation/image_resource.rb', line 57 def create_image_api_image_resource(params={}) service_id = params.fetch(:service_id) resource_id_default = "#{service_id}#{IMAGE_API_DEFAULT_PARAMS}" resource_id = params.fetch(:resource_id, resource_id_default) format = params.fetch(:format, DEFAULT_FORMAT) height = params.fetch(:height, nil) profile = params.fetch(:profile, nil) width = params.fetch(:width, nil) copy_info = params.fetch(:copy_info, false) have_whp = [width, height, profile].all? { |prop| !prop.nil? } remote_info = get_info(service_id) if !have_whp || copy_info resource = self.new resource['id'] = resource_id resource.format = format resource.width = width.nil? ? remote_info['width'] : width resource.height = height.nil? ? remote_info['height'] : height resource_service = Service.new if copy_info resource_service.merge!(remote_info) resource_service['id'] ||= resource_service.delete('@id') else resource_service['id'] = service_id if profile.nil? if remote_info['profile'].kind_of?(Array) resource_service['profile'] = remote_info['profile'][0] else resource_service['profile'] = remote_info['profile'] end else resource_service['profile'] = profile end end resource.service = [resource_service] return resource end |