class IiifS3::ImageInfo

Class ImageInfo is a data object for the JSON representation of the image.

It is designed to support the iiif.io/api/image/2.0/#image-information spec.

Attributes

height[RW]
id[RW]
tile_scale_factors[RW]
tile_width[RW]
width[RW]

Public Class Methods

new(uri, variants, tile_width= nil, tile_scale_factors = nil) click to toggle source
# File lib/iiif_s3/image_info.rb, line 15
def initialize(uri, variants, tile_width= nil, tile_scale_factors = nil)

  raise IiifS3::Error::InvalidImageData, "No full variant provided:  variants: #{variants}" unless variants["full"]
  raise IiifS3::Error::InvalidImageData, "No thumbnail variant provided:  variants: #{variants}" unless variants["thumbnail"]
  raise IiifS3::Error::InvalidImageData, "No URI was provided for this image!" if uri.nil?

  @id = uri
  full = variants["full"]
  @variants = variants
  @width = full.width
  @height = full.height
  @tile_width = tile_width
  @tile_scale_factors = tile_scale_factors
end

Public Instance Methods

context() click to toggle source

@return [String] The IIIF context for this image

# File lib/iiif_s3/image_info.rb, line 75
def context
 IiifS3::IMAGE_CONTEXT
end
profile() click to toggle source

@return [String] The IIIF profile this image supports

# File lib/iiif_s3/image_info.rb, line 85
def profile
  [IiifS3::LEVEL_0,{
    supports: ["cors","sizeByWhListed", "baseUriRedirect"]
  }]
end
protocol() click to toggle source

@return [String] The IIIF protocol for this image

# File lib/iiif_s3/image_info.rb, line 80
def protocol 
  IiifS3::IMAGE_PROTOCOL
end
service() click to toggle source

TODO: Implement this. See <iiif.io/api/annex/services/#physical-dimensions>

# File lib/iiif_s3/image_info.rb, line 92
def service
  return nil
end
sizes() click to toggle source

@return [Hash] a collection of valid sizes based on the available image variants

# File lib/iiif_s3/image_info.rb, line 32
def sizes
   @variants.collect do |name,obj|
    {"width" => obj.width, "height" => obj.height}
  end
end
tiles() click to toggle source

The hash of tile information, or nil if the information does not exist.

@return [Hash, nil] A hash of the tile metadata properly formatted for IIIF JSON.

# File lib/iiif_s3/image_info.rb, line 43
def tiles
  return nil if @tile_scale_factors.nil? || @tile_scale_factors.empty?
  
  return [{
    "width" => @tile_width,
    "scaleFactors" => @tile_scale_factors
  }]
end
to_json() click to toggle source

Generate the JSON data for this image in the IIIF-expected format.

@return [String] the JSON representation of this image

# File lib/iiif_s3/image_info.rb, line 58
def to_json
  obj = {
    "@context" => context,
    "@id" => URI.escape(id),
    "protocol" => protocol,
    "width" => width,
    "height" => height,
    "sizes" => sizes,
    "profile" => profile,
  }
  obj["tiles"] = tiles unless tiles.nil?
  obj["profile"]  = profile
  obj["service"] = service unless service.nil?
  JSON.pretty_generate obj
end