Module: GeoblacklightAdmin::ImageService::IiifManifest
- Defined in:
- app/services/geoblacklight_admin/image_service/iiif_manifest.rb
Class Method Summary collapse
-
.image_url(document, _size) ⇒ String
Formats and returns a thumbnail url from a IIIF Manifest.
Class Method Details
.image_url(document, _size) ⇒ String
Formats and returns a thumbnail url from a IIIF Manifest
56 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 96 97 98 99 100 101 102 103 104 |
# File 'app/services/geoblacklight_admin/image_service/iiif_manifest.rb', line 56 def self.image_url(document, _size) tempfile = Down.download(document.viewer_endpoint) manifest_json = JSON.parse(tempfile.read) # Sequences - Return the first image if it exists # - best case option if manifest_json.dig("sequences", 0, "canvases", 0, "images", 0, "resource", "@id") Rails.logger.debug("\n Image: sequences \n") if manifest_json.dig("sequences", 0, "canvases", 0, "images", 0, "resource", "@id").include?("osu") Rails.logger.debug("\n Image: sequences - OSU variant \n") manifest_json.dig("sequences", 0, "canvases", 0, "images", 0, "resource", "service", "@id") + "/full/1000,/0/default.jpg" else manifest_json.dig("sequences", 0, "canvases", 0, "images", 0, "resource", "@id") end # Items - Return the first item image if it exists # - Northwestern elsif manifest_json.dig("items", 0, "items", 0, "items", 0, "body", "id") Rails.logger.debug("\n Image: items body id \n") manifest_json.dig("items", 0, "items", 0, "items", 0, "body", "id") # Items - Return the first item image if it exists # - strange option elsif manifest_json.dig("items", 0, "items", 0, "items", 0, "id") Rails.logger.debug("\n Image: items id \n") manifest_json.dig("items", 0, "items", 0, "items", 0, "id") # Thumbnail - Return the "thumbnail" if it exists # - varies in size depending on the provider # - worst case option really # - can be @id or id elsif manifest_json["thumbnail"] Rails.logger.debug("\n Image: thumbnail \n") if manifest_json.dig("thumbnail", "@id") manifest_json.dig("thumbnail", "@id") else manifest_json.dig("thumbnail", "id") manifest_json.dig("thumbnail", "id") end # Fail - Gonna fail else Rails.logger.debug("\n Image: failed \n") document.viewer_endpoint end rescue => e Rails.logger.debug("\n Rescued: #{e.inspect} \n") document.viewer_endpoint end |