class WaxIiif::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/wax_iiif/image_info.rb, line 12
def initialize(uri, variants, tile_width = nil, tile_scale_factors = nil)
  raise WaxIiif::Error::InvalidImageData, "No full variant provided:  variants: #{variants}" unless variants['full']
  raise WaxIiif::Error::InvalidImageData, "No thumbnail variant provided:  variants: #{variants}" unless variants['thumbnail']
  raise WaxIiif::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/wax_iiif/image_info.rb, line 68
def context
  WaxIiif::IMAGE_CONTEXT
end
profile() click to toggle source

@return [String] The IIIF profile this image supports

# File lib/wax_iiif/image_info.rb, line 78
def profile
  [WaxIiif::LEVEL_0, {
    supports: %w[cors sizeByWhListed baseUriRedirect]
  }]
end
protocol() click to toggle source

@return [String] The IIIF protocol for this image

# File lib/wax_iiif/image_info.rb, line 73
def protocol
  WaxIiif::IMAGE_PROTOCOL
end
service() click to toggle source

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

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

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

# File lib/wax_iiif/image_info.rb, line 28
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/wax_iiif/image_info.rb, line 38
def tiles
  return nil if @tile_scale_factors.nil? || @tile_scale_factors.empty?

  [{
    'width' => @tile_width,
    'scaleFactors' => @tile_scale_factors
  }]
end
to_json(*_args) 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/wax_iiif/image_info.rb, line 51
def to_json(*_args)
  obj = {
    '@context' => context,
    '@id' => 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