From 341ff7b2173688ff3d01e1668835779bee001723 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 29 Sep 2017 12:44:00 -0500 Subject: [PATCH] Use the iiif-image-api gem for the models --- app/controllers/riiif/images_controller.rb | 4 +- app/models/riiif/image.rb | 20 +-- app/models/riiif/image_information.rb | 31 ++--- app/models/riiif/transformation.rb | 35 ----- app/services/riiif/crop.rb | 129 ++++++++++++++---- .../riiif/imagemagick_command_factory.rb | 7 +- app/services/riiif/kakadu_command_factory.rb | 4 +- app/services/riiif/option_decoder.rb | 89 ------------ app/services/riiif/region/absolute.rb | 23 ---- app/services/riiif/region/full.rb | 23 ---- app/services/riiif/region/percentage.rb | 75 ---------- app/services/riiif/region/square.rb | 45 ------ app/services/riiif/resize.rb | 79 ++++++++++- app/services/riiif/size/absolute.rb | 39 ------ app/services/riiif/size/best_fit.rb | 21 --- app/services/riiif/size/full.rb | 17 --- app/services/riiif/size/height.rb | 26 ---- app/services/riiif/size/percent.rb | 46 ------- app/services/riiif/size/width.rb | 26 ---- app/transformers/riiif/kakadu_transformer.rb | 27 +++- lib/riiif/engine.rb | 1 + riiif.gemspec | 1 + .../riiif/images_controller_spec.rb | 6 +- spec/models/riiif/image_information_spec.rb | 12 +- spec/models/riiif/image_spec.rb | 20 +-- spec/models/riiif/transformation_spec.rb | 42 ------ .../riiif/imagemagick_command_factory_spec.rb | 10 +- .../riiif/kakadu_command_factory_spec.rb | 30 ++-- spec/services/riiif/option_decoder_spec.rb | 87 ------------ spec/services/riiif/region/absolute_spec.rb | 16 --- spec/services/riiif/size/absolute_spec.rb | 15 -- spec/services/riiif/size/height_spec.rb | 11 -- spec/services/riiif/size/width_spec.rb | 11 -- .../riiif/kakadu_transformer_spec.rb | 44 +++--- 34 files changed, 270 insertions(+), 802 deletions(-) delete mode 100644 app/models/riiif/transformation.rb delete mode 100644 app/services/riiif/option_decoder.rb delete mode 100644 app/services/riiif/region/absolute.rb delete mode 100644 app/services/riiif/region/full.rb delete mode 100644 app/services/riiif/region/percentage.rb delete mode 100644 app/services/riiif/region/square.rb delete mode 100644 app/services/riiif/size/absolute.rb delete mode 100644 app/services/riiif/size/best_fit.rb delete mode 100644 app/services/riiif/size/full.rb delete mode 100644 app/services/riiif/size/height.rb delete mode 100644 app/services/riiif/size/percent.rb delete mode 100644 app/services/riiif/size/width.rb delete mode 100644 spec/models/riiif/transformation_spec.rb delete mode 100644 spec/services/riiif/option_decoder_spec.rb delete mode 100644 spec/services/riiif/region/absolute_spec.rb delete mode 100644 spec/services/riiif/size/absolute_spec.rb delete mode 100644 spec/services/riiif/size/height_spec.rb delete mode 100644 spec/services/riiif/size/width_spec.rb diff --git a/app/controllers/riiif/images_controller.rb b/app/controllers/riiif/images_controller.rb index 32abec6..2df80bb 100644 --- a/app/controllers/riiif/images_controller.rb +++ b/app/controllers/riiif/images_controller.rb @@ -2,7 +2,7 @@ module Riiif class ImagesController < ::ApplicationController before_action :link_header, only: [:show, :info] - rescue_from Riiif::InvalidAttributeError do + rescue_from IIIF::Image::InvalidAttributeError do head 400 end @@ -120,7 +120,7 @@ def server_info CONTEXT => CONTEXT_URI, ID => request.original_url.sub('/info.json', ''), PROTOCOL => PROTOCOL_URI, - PROFILE => [LEVEL1, 'formats' => OptionDecoder::OUTPUT_FORMATS] + PROFILE => [LEVEL1, 'formats' => IIIF::Image::OptionDecoder::OUTPUT_FORMATS] } end end diff --git a/app/models/riiif/image.rb b/app/models/riiif/image.rb index 3216327..c52f110 100644 --- a/app/models/riiif/image.rb +++ b/app/models/riiif/image.rb @@ -1,21 +1,5 @@ require 'digest/md5' -## -# These explict requires are needed because in some contexts the Rails -# autoloader can either: unload already loaded classes, or cause a lock while -# trying to load a needed class. -require_dependency 'riiif/region/absolute' -require_dependency 'riiif/region/full' -require_dependency 'riiif/region/percentage' -require_dependency 'riiif/region/square' - -require_dependency 'riiif/size/absolute' -require_dependency 'riiif/size/best_fit' -require_dependency 'riiif/size/full' -require_dependency 'riiif/size/height' -require_dependency 'riiif/size/percent' -require_dependency 'riiif/size/width' - module Riiif class Image extend Deprecation @@ -60,14 +44,14 @@ def render(args) key = Image.cache_key(id, cache_opts) cache.fetch(key, compress: true, expires_in: Image.expires_in) do - file.extract(OptionDecoder.decode(args, info), info) + file.extract(IIIF::Image::OptionDecoder.decode(args), info) end end def info @info ||= begin result = info_service.call(id, file) - ImageInformation.new(result[:width], result[:height]) + ImageInformation.new(width: result[:width], height: result[:height]) end end diff --git a/app/models/riiif/image_information.rb b/app/models/riiif/image_information.rb index 2d38e08..78fc04e 100644 --- a/app/models/riiif/image_information.rb +++ b/app/models/riiif/image_information.rb @@ -1,41 +1,26 @@ module Riiif # This is the result of calling the Riiif.image_info service. It stores the height & width - class ImageInformation + class ImageInformation < IIIF::Image::Dimension extend Deprecation - def initialize(width, height) - @width = width - @height = height + def initialize(*args) + if args.size == 2 + Deprecation.warn(self, 'calling initialize without kwargs is deprecated. Use height: and width:') + super(width: args.first, height: args.second) + else + super + end end - attr_reader :width, :height - def to_h { width: width, height: height } end - def aspect_ratio - width.to_f / height - end - - def [](key) - to_h[key] - end - deprecation_deprecate :[] => 'Riiif::ImageInformation#[] has been deprecated ' \ - 'and will be removed in version 2.0. Use Riiif::ImageInformation#to_h and ' \ - 'call #[] on that result OR consider using #height and #width directly.' - # Image information is only valid if height and width are present. # If an image info service doesn't have the value yet (not characterized perhaps?) # then we wouldn't want to cache this value. def valid? width.present? && height.present? end - - def ==(other) - other.class == self.class && - other.width == width && - other.height == height - end end end diff --git a/app/models/riiif/transformation.rb b/app/models/riiif/transformation.rb deleted file mode 100644 index a516378..0000000 --- a/app/models/riiif/transformation.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Riiif - # Represents a IIIF request - class Transformation - attr_reader :crop, :size, :quality, :rotation, :format - def initialize(crop, size, quality, rotation, format) - @crop = crop - @size = size - @quality = quality - @rotation = rotation - @format = format - end - - # Create a clone of this Transformation, scaled by the factor - # @param [Integer] factor the scale for the new transformation - # @return [Transformation] a new transformation, scaled by factor - def reduce(factor) - Transformation.new(crop.dup, - size.reduce(factor), - quality, - rotation, - format) - end - - # Create a clone of this Transformation, without the crop - # @return [Transformation] a new transformation - # TODO: it would be nice if we didn't need image_info - def without_crop(image_info) - Transformation.new(Region::Full.new(image_info), - size.dup, - quality, - rotation, - format) - end - end -end diff --git a/app/services/riiif/crop.rb b/app/services/riiif/crop.rb index 214b543..6d28e95 100644 --- a/app/services/riiif/crop.rb +++ b/app/services/riiif/crop.rb @@ -1,54 +1,123 @@ module Riiif # Represents a cropping operation class Crop - attr_reader :image_info + # @param transformation [IIIF::Image::Region] the result the user requested + # @param image_info [] + def initialize(region, image_info) + @region = region + @image_info = image_info + end + + attr_reader :image_info, :region # @return [String] a region for imagemagick to decode # (appropriate for passing to the -crop parameter) def to_imagemagick - "#{width}x#{height}+#{offset_x}+#{offset_y}" + case region + when IIIF::Image::Region::Full + nil + when IIIF::Image::Region::Absolute + "#{region.width}x#{region.height}+#{region.offset_x}+#{region.offset_y}" + when IIIF::Image::Region::Square + imagemagick_square + when IIIF::Image::Region::Percent + imagemagick_percent + else + raise "Unknown region #{region.class}" + end end # @return [String] a region for kakadu to decode # (appropriate for passing to the -region parameter) def to_kakadu - "\{#{decimal_offset_y},#{decimal_offset_x}\},\{#{decimal_height},#{decimal_width}\}" + case region + when IIIF::Image::Region::Full + nil + when IIIF::Image::Region::Absolute + "\{#{decimal_offset_y(region.offset_y)},#{decimal_offset_x(region.offset_x)}\}," \ + "\{#{decimal_height(region.height)},#{decimal_width(region.width)}\}" + when IIIF::Image::Region::Square + kakadu_square + when IIIF::Image::Region::Percent + kakadu_percent + else + raise "Unknown region #{region.class}" + end end - attr_reader :offset_x + private - attr_reader :offset_y + def imagemagick_percent + offset_x = (image_info.width * percentage_to_fraction(region.x_pct)).round + offset_y = (image_info.height * percentage_to_fraction(region.y_pct)).round + "#{region.width_pct}%x#{region.height_pct}+#{offset_x}+#{offset_y}" + end - # @return [Integer] the height in pixels - def height - image_info.height - end + def kakadu_percent + offset_x = (image_info.width * percentage_to_fraction(region.x_pct)).round + offset_y = (image_info.height * percentage_to_fraction(region.y_pct)).round + "\{#{decimal_offset_y(offset_y)},#{decimal_offset_x(offset_x)}\}," \ + "\{#{percentage_to_fraction(region.height_pct)},#{percentage_to_fraction(region.width_pct)}\}" + end - # @return [Integer] the width in pixels - def width - image_info.width - end + def kakadu_square + min, max = [image_info.width, image_info.height].minmax + offset = (max - min) / 2 + if image_info.height >= image_info.width + # Portrait + "\{#{decimal_height(offset)},0\}," \ + "\{#{decimal_height(image_info.height)},#{decimal_width(image_info.height)}\}" + else + # Landscape + "\{0,#{decimal_width(offset)}\}," \ + "\{#{decimal_height(image_info.width)},#{decimal_width(image_info.width)}\}" + end + end - # @return [Float] the fractional height with respect to the original size - def decimal_height(n = height) - n.to_f / image_info.height - end + def imagemagick_square + min, max = [image_info.width, image_info.height].minmax + offset = (max - min) / 2 + if image_info.height >= image_info.width + "#{min}x#{min}+0+#{offset}" + else + "#{min}x#{min}+#{offset}+0" + end + end - # @return [Float] the fractional width with respect to the original size - def decimal_width(n = width) - n.to_f / image_info.width - end + # @return [Integer] the height in pixels + def height + image_info.height + end - def decimal_offset_x - offset_x.to_f / image_info.width - end + # @return [Integer] the width in pixels + def width + image_info.width + end - def decimal_offset_y - offset_y.to_f / image_info.height - end + # @return [Float] the fractional height with respect to the original size + def decimal_height(n = height) + n.to_f / image_info.height + end - def maintain_aspect_ratio? - (height / width) == (image_info.height / image_info.width) - end + # @return [Float] the fractional width with respect to the original size + def decimal_width(n = width) + n.to_f / image_info.width + end + + def decimal_offset_x(offset_x) + offset_x.to_f / image_info.width + end + + def decimal_offset_y(offset_y) + offset_y.to_f / image_info.height + end + + def maintain_aspect_ratio? + (height / width) == (image_info.height / image_info.width) + end + + def percentage_to_fraction(n) + n / 100.0 + end end end diff --git a/app/services/riiif/imagemagick_command_factory.rb b/app/services/riiif/imagemagick_command_factory.rb index 8a98ba9..55d8d3d 100644 --- a/app/services/riiif/imagemagick_command_factory.rb +++ b/app/services/riiif/imagemagick_command_factory.rb @@ -54,17 +54,18 @@ def output end def crop - directive = transformation.crop.to_imagemagick + directive = Crop.new(transformation.region, info).to_imagemagick " -crop #{directive}" if directive end def size - directive = transformation.size.to_imagemagick + directive = Resize.new(transformation.size, info).to_imagemagick " -resize #{directive}" if directive end def rotation - " -virtual-pixel white +distort srt #{transformation.rotation}" if transformation.rotation + return if transformation.rotation.zero? + " -virtual-pixel white +distort srt #{transformation.rotation}" end def quality diff --git a/app/services/riiif/kakadu_command_factory.rb b/app/services/riiif/kakadu_command_factory.rb index 55cdee9..f84422d 100644 --- a/app/services/riiif/kakadu_command_factory.rb +++ b/app/services/riiif/kakadu_command_factory.rb @@ -25,7 +25,7 @@ def command(tmp_file) end def reduction_factor - @reduction_factor ||= transformation.size.reduction_factor + @reduction_factor ||= Resize.new(transformation.size, info).reduction_factor end private @@ -47,7 +47,7 @@ def quiet end def region - region_arg = transformation.crop.to_kakadu + region_arg = Crop.new(transformation.region, info).to_kakadu " -region \"#{region_arg}\"" if region_arg end diff --git a/app/services/riiif/option_decoder.rb b/app/services/riiif/option_decoder.rb deleted file mode 100644 index 4195046..0000000 --- a/app/services/riiif/option_decoder.rb +++ /dev/null @@ -1,89 +0,0 @@ -module Riiif - # Decodes the URL parameters into a Transformation object - class OptionDecoder - OUTPUT_FORMATS = %w(jpg png).freeze - - # a helper method for instantiating the OptionDecoder - # @param [ActiveSupport::HashWithIndifferentAccess] options - # @param [ImageInformation] image_info - def self.decode(options, image_info) - new(options, image_info).decode - end - - # @param [ActiveSupport::HashWithIndifferentAccess] options - # @param [ImageInformation] image_info - def initialize(options, image_info) - @options = options - @image_info = image_info - end - - attr_reader :image_info - - ## - # @return [Transformation] - def decode - raise ArgumentError, "You must provide a format. You provided #{@options}" unless @options[:format] - validate_format!(@options[:format]) - Riiif::Transformation.new(decode_region(@options.delete(:region)), - decode_size(@options.delete(:size)), - decode_quality(@options[:quality]), - decode_rotation(@options[:rotation]), - @options[:format]) - end - - def decode_quality(quality) - return if quality.nil? || %w(default color).include?(quality) - return quality if %w(bitonal grey).include?(quality) - raise InvalidAttributeError, "Unsupported quality: #{quality}" - end - - def decode_rotation(rotation) - return if rotation.nil? || rotation == '0' - begin - Float(rotation) - rescue ArgumentError - raise InvalidAttributeError, "Unsupported rotation: #{rotation}" - end - end - - def validate_format!(format) - raise InvalidAttributeError, "Unsupported format: #{format}" unless OUTPUT_FORMATS.include?(format) - end - - # rubocop:disable Metrics/AbcSize - def decode_region(region) - if region.nil? || region == 'full' - Riiif::Region::Full.new(image_info) - elsif md = /^pct:(\d+(?:.\d+)?),(\d+(?:.\d+)?),(\d+(?:.\d+)?),(\d+(?:.\d+)?)$/.match(region) - Riiif::Region::Percentage - .new(image_info, md[1].to_f, md[2].to_f, md[3].to_f, md[4].to_f) - elsif md = /^(\d+),(\d+),(\d+),(\d+)$/.match(region) - Riiif::Region::Absolute.new(image_info, md[1].to_i, md[2].to_i, md[3].to_i, md[4].to_i) - elsif region == 'square' - Riiif::Region::Square.new(image_info) - else - raise InvalidAttributeError, "Invalid region: #{region}" - end - end - - # rubocop:disable Metrics/PerceivedComplexity - def decode_size(size) - if size.nil? || size == 'full' - Riiif::Size::Full.new - elsif md = /^,(\d+)$/.match(size) - Riiif::Size::Height.new(image_info, md[1].to_i) - elsif md = /^(\d+),$/.match(size) - Riiif::Size::Width.new(image_info, md[1].to_i) - elsif md = /^pct:(\d+(?:.\d+)?)$/.match(size) - Riiif::Size::Percent.new(image_info, md[1].to_f) - elsif md = /^(\d+),(\d+)$/.match(size) - Riiif::Size::Absolute.new(image_info, md[1].to_i, md[2].to_i) - elsif md = /^!(\d+),(\d+)$/.match(size) - Riiif::Size::BestFit.new(image_info, md[1].to_i, md[2].to_i) - else - raise InvalidAttributeError, "Invalid size: #{size}" - end - end - # rubocop:enable Metrics/PerceivedComplexity, Metrics/AbcSize - end -end diff --git a/app/services/riiif/region/absolute.rb b/app/services/riiif/region/absolute.rb deleted file mode 100644 index ce70b80..0000000 --- a/app/services/riiif/region/absolute.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Riiif - module Region - # Represents an absolute specified region - class Absolute < Crop - # TODO: only kakadu needs image_info. So there's potenial to optimize by - # making image_info a proxy that fetches the info lazily when needed. - # @param [ImageInformation] image_info - # @param [Integer] x - # @param [Integer] y - # @param [Integer] width - # @param [Integer] height - def initialize(image_info, x, y, width, height) - @image_info = image_info - @offset_x = x - @offset_y = y - @width = width - @height = height - end - - attr_reader :width, :height - end - end -end diff --git a/app/services/riiif/region/full.rb b/app/services/riiif/region/full.rb deleted file mode 100644 index 554e196..0000000 --- a/app/services/riiif/region/full.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Riiif - module Region - # Represents the image or region requested at its full size. - # This is a nil crop operation. - class Full < Crop - def initialize(image_info) - @image_info = image_info - end - - # @return [NilClass] a region for imagemagick to decode - # the nil implies no cropping needed - def to_imagemagick - nil - end - - # @return [NilClass] a region for kakadu to decode - # the nil implies no cropping needed - def to_kakadu - nil - end - end - end -end diff --git a/app/services/riiif/region/percentage.rb b/app/services/riiif/region/percentage.rb deleted file mode 100644 index 1b43b27..0000000 --- a/app/services/riiif/region/percentage.rb +++ /dev/null @@ -1,75 +0,0 @@ -module Riiif - module Region - # represents request cooridnates specified as percentage - class Percentage < Crop - # @param info [ImageInformation] - # @param x [Float] - # @param y [Float] - # @param width [Float] - # @param height [Float] - def initialize(image_info, x, y, width, height) - @image_info = image_info - @x_pct = x - @y_pct = y - @width_pct = width - @height_pct = height - end - - attr_reader :x_pct, :y_pct, :width_pct, :height_pct - - # From the Imagemagick docs: - # The percentage symbol '%' can appear anywhere in a argument, and if - # given will refer to both width and height numbers. It is a flag that - # just declares that the 'image size' parts are a percentage fraction - # of the images virtual canvas or page size. Offsets are always given - # in pixels. - # @return [String] a region for imagemagick to decode - # (appropriate for passing to the -crop parameter) - def to_imagemagick - "#{width_pct}%x#{height_pct}+#{offset_x}+#{offset_y}" - end - - def maintain_aspect_ratio? - width_pct == height_pct - end - - private - - # @param [Float] n a percentage to convert - # @return [Float] - def percentage_to_fraction(n) - n / 100.0 - end - - # @return [Integer] - def offset_x - (@image_info.width * percentage_to_fraction(x_pct)).round - end - - # @return [Integer] - def offset_y - (@image_info.height * percentage_to_fraction(y_pct)).round - end - - # @return [Float] - def decimal_height - percentage_to_fraction(height_pct) - end - - # @return [Float] - def decimal_width - percentage_to_fraction(width_pct) - end - - # @return [Float] - def decimal_offset_y - percentage_to_fraction(y_pct) - end - - # @return [Float] - def decimal_offset_x - percentage_to_fraction(x_pct) - end - end - end -end diff --git a/app/services/riiif/region/square.rb b/app/services/riiif/region/square.rb deleted file mode 100644 index cbed015..0000000 --- a/app/services/riiif/region/square.rb +++ /dev/null @@ -1,45 +0,0 @@ -module Riiif - module Region - # Represents requested square cooridnates - class Square < Crop - def initialize(image_info) - @image_info = image_info - @min, @max = [@image_info.width, @image_info.height].minmax - @offset = (@max - @min) / 2 - end - - # @return [String] a square region for imagemagick to decode - # (appropriate for passing to the -crop parameter) - def to_imagemagick - if @image_info.height >= @image_info.width - "#{height}x#{width}+0+#{@offset}" - else - "#{height}x#{width}+#{@offset}+0" - end - end - - # @return [String] a region for kakadu to decode - # (appropriate for passing to the -region parameter) - def to_kakadu - # (top, left, height, width) - if @image_info.height >= @image_info.width - # Portrait - "\{#{decimal_height(@offset)},0\}," \ - "\{#{decimal_height(height)},#{decimal_width(height)}\}" - else - # Landscape - "\{0,#{decimal_width(@offset)}\}," \ - "\{#{decimal_height(width)},#{decimal_width(width)}\}" - end - end - - def height - @min - end - - def width - @min - end - end - end -end diff --git a/app/services/riiif/resize.rb b/app/services/riiif/resize.rb index ad08d4c..d0eed7c 100644 --- a/app/services/riiif/resize.rb +++ b/app/services/riiif/resize.rb @@ -1,30 +1,89 @@ module Riiif # Represents a resize operation class Resize - attr_reader :image_info + # @param size [IIIF::Image::Size] the result the user requested + # @param image_info [] + def initialize(size, image_info) + @size = size + @image_info = image_info + end + + attr_reader :image_info, :size + + # @return [String] a resize directive for imagemagick to use + def to_imagemagick + case size + when IIIF::Image::Size::Percent + "#{size.percentage}%" + when IIIF::Image::Size::Width + size.width + when IIIF::Image::Size::Height + "x#{size.height}" + when IIIF::Image::Size::Absolute + "#{size.width}x#{size.height}!" + when IIIF::Image::Size::BestFit + "#{size.width}x#{size.height}" + when IIIF::Image::Size::Max, IIIF::Image::Size::Full + nil + else + raise "unknown size #{size.class}" + end + end # @return [Integer] the height in pixels def height - image_info.height + case size + when IIIF::Image::Size::Absolute + size.height + when IIIF::Image::Size::Percent + image_info.height * Integer(size.percentage).to_f / 100 + when IIIF::Image::Size::Width + size.height_for_aspect_ratio(image_info.aspect) + else + image_info.height + end end # @return [Integer] the width in pixels def width - image_info.width + case size + when IIIF::Image::Size::Absolute + size.width + when IIIF::Image::Size::Percent + image_info.width * Integer(size.percentage).to_f / 100 + when IIIF::Image::Size::Height + size.width_for_aspect_ratio(image_info.aspect) + else + image_info.width + end end # Should we reduce this image with KDU? def reduce? - true + case size + when IIIF::Image::Size::Full, IIIF::Image::Size::Max + false + when IIIF::Image::Size::Absolute + aspect_ratio = width.to_f / height + in_delta?(image_info.aspect, aspect_ratio, 0.001) + else + true + end end # This is used for a second resize by imagemagick after resizing # by kdu. # No need to scale most resize operations (only percent) # @param [Integer] factor to scale by - # @return [Absolute] a copy of self if factor is zero. - def reduce(_factor) - dup + # @return [IIIF::Image::Size] a copy of self if factor is zero. + def reduce(factor) + case size + when IIIF::Image::Size::Percent + pct = size.percentage * 2**factor + IIIF::Image::Size::Percent.new(pct) + else + size.dup + end end # @return [Integer] the reduction factor for this operation @@ -41,5 +100,11 @@ def reduction_factor(max_factor = 5) end factor end + + private + + def in_delta?(x1, x2, delta) + (x1 - x2).abs <= delta + end end end diff --git a/app/services/riiif/size/absolute.rb b/app/services/riiif/size/absolute.rb deleted file mode 100644 index c6a479c..0000000 --- a/app/services/riiif/size/absolute.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Riiif - module Size - # The width and height of the returned image are exactly w and h. - # The aspect ratio of the returned image may be different than the extracted - # region, resulting in a distorted image. - class Absolute < Resize - # @param [ImageInformation] info - # @param [Integer] width - # @param [Integer] height - def initialize(info, width, height) - @image_info = info - @width = width - @height = height - end - - # @return [String] a resize directive for imagemagick to use - def to_imagemagick - "#{@width}x#{@height}!" - end - - attr_reader :height, :width - - # Reduce this if the aspect ratio of the image is maintained. - def reduce? - in_delta?(image_info.aspect_ratio, aspect_ratio, 0.001) - end - - private - - def aspect_ratio - width.to_f / height - end - - def in_delta?(x1, x2, delta) - (x1 - x2).abs <= delta - end - end - end -end diff --git a/app/services/riiif/size/best_fit.rb b/app/services/riiif/size/best_fit.rb deleted file mode 100644 index 8ecdd6a..0000000 --- a/app/services/riiif/size/best_fit.rb +++ /dev/null @@ -1,21 +0,0 @@ -module Riiif - module Size - # The image content is scaled for the best fit such that the resulting width and - # height are less than or equal to the requested width and height. - class BestFit < Resize - # @param [ImageInformation] info - # @param [Integer] width - # @param [Integer] height - def initialize(info, width, height) - @image_info = info - @width = width - @height = height - end - - # @return [String] a resize directive for imagemagick to use - def to_imagemagick - "#{@width}x#{@height}" - end - end - end -end diff --git a/app/services/riiif/size/full.rb b/app/services/riiif/size/full.rb deleted file mode 100644 index 5a4aa59..0000000 --- a/app/services/riiif/size/full.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Riiif - module Size - # represents requested full size - class Full < Resize - # @return [NilClass] a size for imagemagick to decode - # the nil implies no resizing needed - def to_imagemagick - nil - end - - # Should we reduce this image? - def reduce? - false - end - end - end -end diff --git a/app/services/riiif/size/height.rb b/app/services/riiif/size/height.rb deleted file mode 100644 index 8917c17..0000000 --- a/app/services/riiif/size/height.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Riiif - module Size - # The image or region should be scaled so that its height is exactly equal - # to the provided parameter, and the width will be a calculated value that - # maintains the aspect ratio of the extracted region - class Height < Resize - # @param [ImageInformation] info - # @param [Integer] height - def initialize(info, height) - @image_info = info - @height = height - end - - # @return [String] a resize directive for imagemagick to use - def to_imagemagick - "x#{@height}" - end - - def width - height * image_info.width / image_info.height - end - - attr_reader :height - end - end -end diff --git a/app/services/riiif/size/percent.rb b/app/services/riiif/size/percent.rb deleted file mode 100644 index 6d0e008..0000000 --- a/app/services/riiif/size/percent.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Riiif - module Size - # The width and height of the returned image is scaled to n% of the width and height - # of the extracted region. The aspect ratio of the returned image is the same as that - # of the extracted region. - class Percent < Resize - # @param info [ImageInformation] - # @param percentage [Float] - def initialize(info, percentage) - @image_info = info - @percentage = percentage - end - - attr_reader :percentage - - # @return [String] a resize directive for imagemagick to use - def to_imagemagick - "#{percentage}%" - end - - # @return [Integer] the height in pixels - def height - percent_of(image_info.height) - end - - # @return [Integer] the width in pixels - def width - percent_of(image_info.width) - end - - # @param [Integer] factor number of times to reduce by 1/2 - def reduce(factor) - pct = percentage * 2**factor - Percent.new(image_info, pct) - end - - private - - # @param [Integer] value a value to convert to the percentage - # @return [Float] - def percent_of(value) - value * Integer(percentage).to_f / 100 - end - end - end -end diff --git a/app/services/riiif/size/width.rb b/app/services/riiif/size/width.rb deleted file mode 100644 index 5499d22..0000000 --- a/app/services/riiif/size/width.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Riiif - module Size - # The image or region should be scaled so that its width is exactly equal - # to the provided parameter, and the height will be a calculated value that - # maintains the aspect ratio of the extracted region - class Width < Resize - # @param [ImageInformation] info - # @param [Integer] width - def initialize(info, width) - @image_info = info - @width = width - end - - # @return [String] a resize directive for imagemagick to use - def to_imagemagick - @width.to_s - end - - attr_reader :width - - def height - width * image_info.height / image_info.width - end - end - end -end diff --git a/app/transformers/riiif/kakadu_transformer.rb b/app/transformers/riiif/kakadu_transformer.rb index fde9d7e..9f16b6b 100644 --- a/app/transformers/riiif/kakadu_transformer.rb +++ b/app/transformers/riiif/kakadu_transformer.rb @@ -23,15 +23,38 @@ def with_tempfile def post_process(intermediate_file, reduction_factor) # Calculate a new set of transforms with respect to reduction_factor transformation = if reduction_factor - self.transformation.without_crop(image_info).reduce(reduction_factor) + reduce(without_crop, reduction_factor) else - self.transformation.without_crop(image_info) + without_crop end Riiif::File.new(intermediate_file).extract(transformation, image_info) end private + # Create a clone of the Transformation, without the crop + # @return [IIIF::Image::Transformation] a new transformation + def without_crop + IIIF::Image::Transformation.new(region: IIIF::Image::Region::Full.new, + size: transformation.size.dup, + quality: transformation.quality, + rotation: transformation.rotation, + format: transformation.format) + end + + # Create a clone of this Transformation, scaled by the factor + # @param [IIIF::Image::Transformation] transformation the transformation to clone + # @param [Integer] factor the scale for the new transformation + # @return [Transformation] a new transformation, scaled by factor + def reduce(transformation, factor) + resize = Resize.new(transformation.size, image_info) + IIIF::Image::Transformation.new(region: transformation.region.dup, + size: resize.reduce(factor), + quality: transformation.quality, + rotation: transformation.rotation, + format: transformation.format) + end + def tmp_path @link_path ||= LinkNameService.create end diff --git a/lib/riiif/engine.rb b/lib/riiif/engine.rb index d163c8d..56bae5a 100644 --- a/lib/riiif/engine.rb +++ b/lib/riiif/engine.rb @@ -1,3 +1,4 @@ +require 'iiif-image-api' module Riiif class Engine < ::Rails::Engine require 'riiif/rails/routes' diff --git a/riiif.gemspec b/riiif.gemspec index ca9e690..962b096 100644 --- a/riiif.gemspec +++ b/riiif.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'railties', '>= 4.2', '<6' spec.add_dependency 'deprecation', '>= 1.0.0' + spec.add_dependency 'iiif-image-api', '~> 0.1.0' spec.add_development_dependency 'bundler', '~> 1.3' spec.add_development_dependency 'rake' spec.add_development_dependency 'engine_cart', '~> 0.8' diff --git a/spec/controllers/riiif/images_controller_spec.rb b/spec/controllers/riiif/images_controller_spec.rb index c3537aa..c5db46c 100644 --- a/spec/controllers/riiif/images_controller_spec.rb +++ b/spec/controllers/riiif/images_controller_spec.rb @@ -72,7 +72,7 @@ context 'with a invalid region' do it 'renders 400' do image = double('an image') - allow(image).to receive(:render).and_raise Riiif::InvalidAttributeError + allow(image).to receive(:render).and_raise IIIF::Image::InvalidAttributeError allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image) get :show, params: { id: 'abcd1234', action: 'show', region: '`szoW0', size: 'full', rotation: '0', quality: 'default', format: 'jpg' } @@ -138,7 +138,7 @@ before do allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image) - allow(image).to receive(:info).and_return(Riiif::ImageInformation.new(6000, 4000)) + allow(image).to receive(:info).and_return(Riiif::ImageInformation.new(width: 6000, height: 4000)) end it 'returns info' do @@ -163,7 +163,7 @@ before do allow(Riiif::Image).to receive(:new).with('abcd1234').and_return(image) - allow(image).to receive(:info).and_return(Riiif::ImageInformation.new(nil, nil)) + allow(image).to receive(:info).and_return(Riiif::ImageInformation.new(width: nil, height: nil)) end it 'returns an error' do diff --git a/spec/models/riiif/image_information_spec.rb b/spec/models/riiif/image_information_spec.rb index c2f1f83..de8dc4c 100644 --- a/spec/models/riiif/image_information_spec.rb +++ b/spec/models/riiif/image_information_spec.rb @@ -5,23 +5,15 @@ subject { info.valid? } context 'with valid dimensions' do - let(:info) { described_class.new(100, 200) } + let(:info) { described_class.new(width: 100, height: 200) } it { is_expected.to be true } end context 'with nil dimensions' do - let(:info) { described_class.new(nil, nil) } + let(:info) { described_class.new(width: nil, height: nil) } it { is_expected.to be false } end end - - describe '#[]' do - subject { info[:width] } - let(:info) { described_class.new(100, 200) } - before { allow(Deprecation).to receive(:warn) } - - it { is_expected.to eq 100 } - end end diff --git a/spec/models/riiif/image_spec.rb b/spec/models/riiif/image_spec.rb index bec07b3..cffcbe4 100644 --- a/spec/models/riiif/image_spec.rb +++ b/spec/models/riiif/image_spec.rb @@ -30,18 +30,12 @@ it 'is able to override the file used for the Image' do img = described_class.new('some_id', Riiif::File.new(filename)) expect(img.id).to eq 'some_id' - expect(img.info).to eq Riiif::ImageInformation.new(800, 400) - end - - describe 'without a format' do - it 'raises an error' do - expect { subject.render('size' => 'full') }.to raise_error ArgumentError - end + expect(img.info).to eq Riiif::ImageInformation.new(width: 800, height: 400) end describe 'info' do it 'returns the data' do - expect(subject.info).to eq Riiif::ImageInformation.new(800, 400) + expect(subject.info).to eq Riiif::ImageInformation.new(width: 800, height: 400) end end @@ -59,7 +53,7 @@ describe 'get info' do subject { described_class.new('Cave_26,_Ajanta') } it 'is easy' do - expect(subject.info).to eq Riiif::ImageInformation.new(600, 390) + expect(subject.info).to eq Riiif::ImageInformation.new(width: 600, height: 390) end end @@ -127,7 +121,7 @@ let(:region) { '150x75' } it 'raises an error' do - expect { render }.to raise_error Riiif::InvalidAttributeError + expect { render }.to raise_error IIIF::Image::InvalidAttributeError end end end @@ -208,7 +202,7 @@ let(:size) { '150x75' } it 'raises an error' do - expect { render }.to raise_error Riiif::InvalidAttributeError + expect { render }.to raise_error IIIF::Image::InvalidAttributeError end end end @@ -240,7 +234,7 @@ let(:rotation) { '150x' } it 'raises an error for invalid angle' do - expect { render }.to raise_error Riiif::InvalidAttributeError + expect { render }.to raise_error IIIF::Image::InvalidAttributeError end end end @@ -292,7 +286,7 @@ let(:quality) { 'best' } it 'raises an error' do - expect { render }.to raise_error Riiif::InvalidAttributeError + expect { render }.to raise_error IIIF::Image::InvalidAttributeError end end end diff --git a/spec/models/riiif/transformation_spec.rb b/spec/models/riiif/transformation_spec.rb deleted file mode 100644 index c462459..0000000 --- a/spec/models/riiif/transformation_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Riiif::Transformation do - subject(:transformation) do - Riiif::Transformation.new(region, - size, - quality, - rotation, - fmt) - end - - let(:region) { Riiif::Region::Full.new(image_info) } - let(:size) { Riiif::Size::Percent.new(image_info, 20) } - let(:quality) { nil } - let(:rotation) { nil } - let(:fmt) { nil } - let(:image_info) { double('Image info', height: 4381, width: 6501) } - - describe 'reduce' do - subject { transformation.reduce(factor) } - context 'when reduced by 2' do - let(:factor) { 2 } - let(:size) { Riiif::Size::Percent.new(image_info, 20) } - - it 'downsamples the size' do - expect(subject.size).to be_kind_of Riiif::Size::Percent - expect(subject.size.percentage).to eq 80.0 - end - end - end - - describe 'without_crop' do - let(:region) { Riiif::Region::Absolute.new(image_info, 5, 6, 7, 8) } - - subject { transformation.without_crop(image_info) } - it 'nullifies the crop' do - expect(subject.crop).to be_kind_of Riiif::Region::Full - end - end -end diff --git a/spec/services/riiif/imagemagick_command_factory_spec.rb b/spec/services/riiif/imagemagick_command_factory_spec.rb index 02c8879..d008c4d 100644 --- a/spec/services/riiif/imagemagick_command_factory_spec.rb +++ b/spec/services/riiif/imagemagick_command_factory_spec.rb @@ -9,11 +9,11 @@ let(:instance) { described_class.new(path, info, transformation) } let(:transformation) do - Riiif::Transformation.new(Riiif::Region::Full.new(info), - Riiif::Size::Full.new, - 'quality', - 'rotation', - format) + IIIF::Image::Transformation.new(region: IIIF::Image::Region::Full.new, + size: IIIF::Image::Size::Full.new, + quality: 'quality', + rotation: 15.2, + format: format) end context "when it's a jpeg" do diff --git a/spec/services/riiif/kakadu_command_factory_spec.rb b/spec/services/riiif/kakadu_command_factory_spec.rb index 9fb7e2d..b72cc20 100644 --- a/spec/services/riiif/kakadu_command_factory_spec.rb +++ b/spec/services/riiif/kakadu_command_factory_spec.rb @@ -7,18 +7,18 @@ let(:info) { double(:info) } let(:path) { 'foo.jp2' } - let(:region) { Riiif::Region::Full.new(info) } - let(:size) { Riiif::Size::Full.new } + let(:region) { IIIF::Image::Region::Full.new } + let(:size) { IIIF::Image::Size::Full.new } let(:quality) { nil } let(:rotation) { nil } let(:fmt) { nil } let(:transformation) do - Riiif::Transformation.new(region, - size, - quality, - rotation, - fmt) + IIIF::Image::Transformation.new(region: region, + size: size, + quality: quality, + rotation: rotation, + format: fmt) end describe '#command' do @@ -38,17 +38,17 @@ end context 'with absolute' do - let(:region) { Riiif::Region::Absolute.new(info, 25, 75, 150, 100) } + let(:region) { IIIF::Image::Region::Absolute.new(25, 75, 150, 100) } it { is_expected.to eq ' -region "{0.25,0.08333333333333333},{0.3333333333333333,0.5}"' } end context 'with a square' do - let(:region) { Riiif::Region::Square.new(info) } + let(:region) { IIIF::Image::Region::Square.new } it { is_expected.to eq ' -region "{0.0,0},{1.0,1.0}"' } end context 'with a percentage' do - let(:region) { Riiif::Region::Percentage.new(info, 20.0, 30.0, 40.0, 50.0) } + let(:region) { IIIF::Image::Region::Percent.new(20.0, 30.0, 40.0, 50.0) } it { is_expected.to eq ' -region "{0.3,0.2},{0.5,0.4}"' } end end @@ -56,29 +56,29 @@ describe '#reduction_factor' do subject { instance.send(:reduction_factor) } - let(:info) { Riiif::ImageInformation.new(300, 300) } + let(:info) { Riiif::ImageInformation.new(width: 300, height: 300) } context 'for a full size image' do it { is_expected.to eq nil } end context 'when the aspect ratio is maintined for absolute' do - let(:size) { Riiif::Size::Absolute.new(info, 145, 145) } + let(:size) { IIIF::Image::Size::Absolute.new(145, 145) } it { is_expected.to eq 1 } end context 'when the aspect ratio is not-maintined' do - let(:size) { Riiif::Size::Absolute.new(info, 100, 145) } + let(:size) { IIIF::Image::Size::Absolute.new(100, 145) } it { is_expected.to eq nil } end context 'when aspect ratio is maintained for 45 pct' do - let(:size) { Riiif::Size::Percent.new(info, 45.0) } + let(:size) { IIIF::Image::Size::Percent.new(45.0) } it { is_expected.to eq 1 } end context 'when aspect ratio is maintained for 20 pct' do - let(:size) { Riiif::Size::Percent.new(info, 20.0) } + let(:size) { IIIF::Image::Size::Percent.new(20.0) } it { is_expected.to eq 2 } end end diff --git a/spec/services/riiif/option_decoder_spec.rb b/spec/services/riiif/option_decoder_spec.rb deleted file mode 100644 index f6fe936..0000000 --- a/spec/services/riiif/option_decoder_spec.rb +++ /dev/null @@ -1,87 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Riiif::OptionDecoder do - let(:instance) { described_class.new(options, image_info) } - let(:image_info) { double } - let(:options) { double } - - describe '#decode_region' do - subject(:region) { instance.decode_region(value) } - - context 'when passed a percentage' do - context 'that has int like values' do - let(:value) { 'pct:1,2,3,4' } - it 'deals with them' do - expect(region).to be_kind_of Riiif::Region::Percentage - expect(region.x_pct).to eq 1.0 - expect(region.y_pct).to eq 2.0 - expect(region.width_pct).to eq 3.0 - expect(region.height_pct).to eq 4.0 - end - end - - context 'that has float like values' do - let(:value) { 'pct:1.0,2.3,3.0,4.0' } - it 'deals with them' do - expect(region).to be_kind_of Riiif::Region::Percentage - expect(region.x_pct).to eq 1.0 - expect(region.y_pct).to eq 2.3 - expect(region.width_pct).to eq 3.0 - expect(region.height_pct).to eq 4.0 - end - end - end - end - - describe '#decode_size' do - subject(:size) { instance.decode_size(value) } - - context 'when passed a percentage' do - context 'that has int like values' do - let(:value) { 'pct:10' } - it 'deals with them' do - expect(size).to be_kind_of Riiif::Size::Percent - expect(size.percentage).to eq 10.0 - end - end - - context 'that has float like values' do - let(:value) { 'pct:10.0010000' } - it 'deals with them' do - expect(size).to be_kind_of Riiif::Size::Percent - expect(size.percentage).to eq 10.001 - end - end - end - - context 'when passed a width' do - let(:value) { '145,' } - - it 'casts width to an integer' do - expect(size).to be_kind_of Riiif::Size::Width - expect(size.width).to eq 145 - end - end - - context 'when passed a height' do - let(:value) { ',50' } - - it 'casts height to an integer' do - expect(size).to be_kind_of Riiif::Size::Height - expect(size.height).to eq 50 - end - end - - context 'when passed an absolute' do - let(:value) { '145,50' } - - it 'casts values to integers' do - expect(size).to be_kind_of Riiif::Size::Absolute - expect(size.width).to eq 145 - expect(size.height).to eq 50 - end - end - end -end diff --git a/spec/services/riiif/region/absolute_spec.rb b/spec/services/riiif/region/absolute_spec.rb deleted file mode 100644 index 44ee416..0000000 --- a/spec/services/riiif/region/absolute_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'spec_helper' - -RSpec.describe Riiif::Region::Absolute do - let(:image_info) { double } - let(:instance) { described_class.new(image_info, 5, 15, 50, 100) } - - describe 'height' do - subject { instance.height } - it { is_expected.to eq 100 } - end - - describe 'width' do - subject { instance.width } - it { is_expected.to eq 50 } - end -end diff --git a/spec/services/riiif/size/absolute_spec.rb b/spec/services/riiif/size/absolute_spec.rb deleted file mode 100644 index dcbd9b9..0000000 --- a/spec/services/riiif/size/absolute_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -RSpec.describe Riiif::Size::Absolute do - let(:image_info) { double } - let(:instance) { described_class.new(image_info, 50, 100) } - describe 'height' do - subject { instance.height } - it { is_expected.to eq 100 } - end - - describe 'width' do - subject { instance.width } - it { is_expected.to eq 50 } - end -end diff --git a/spec/services/riiif/size/height_spec.rb b/spec/services/riiif/size/height_spec.rb deleted file mode 100644 index 47979aa..0000000 --- a/spec/services/riiif/size/height_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -RSpec.describe Riiif::Size::Height do - let(:image_info) { double } - let(:instance) { described_class.new(image_info, 100) } - - describe 'height' do - subject { instance.height } - it { is_expected.to eq 100 } - end -end diff --git a/spec/services/riiif/size/width_spec.rb b/spec/services/riiif/size/width_spec.rb deleted file mode 100644 index f524256..0000000 --- a/spec/services/riiif/size/width_spec.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'spec_helper' - -RSpec.describe Riiif::Size::Width do - let(:image_info) { double } - let(:instance) { described_class.new(image_info, 50) } - - describe 'width' do - subject { instance.width } - it { is_expected.to eq 50 } - end -end diff --git a/spec/transformers/riiif/kakadu_transformer_spec.rb b/spec/transformers/riiif/kakadu_transformer_spec.rb index 9f9b056..d2be599 100644 --- a/spec/transformers/riiif/kakadu_transformer_spec.rb +++ b/spec/transformers/riiif/kakadu_transformer_spec.rb @@ -5,20 +5,20 @@ RSpec.describe Riiif::KakaduTransformer do subject(:instance) { described_class.new(path, image_info, transformation) } - let(:image_info) { Riiif::ImageInformation.new(6501, 4381) } + let(:image_info) { Riiif::ImageInformation.new(width: 6501, height: 4381) } let(:path) { 'baseball.jp2' } - let(:region) { Riiif::Region::Full.new(image_info) } - let(:size) { Riiif::Size::Full.new } + let(:region) { IIIF::Image::Region::Full.new } + let(:size) { IIIF::Image::Size::Full.new } let(:quality) { nil } - let(:rotation) { nil } + let(:rotation) { 0 } let(:fmt) { 'jpg' } let(:transformation) do - Riiif::Transformation.new(region, - size, - quality, - rotation, - fmt) + IIIF::Image::Transformation.new(region: region, + size: size, + quality: quality, + rotation: rotation, + format: fmt) end describe '#transform' do @@ -32,10 +32,10 @@ context 'resize and region' do # This is the validator test for size_region - let(:size) { Riiif::Size::Absolute.new(image_info, 38, 38) } - let(:region) { Riiif::Region::Absolute.new(image_info, 200, 100, 100, 100) } + let(:size) { IIIF::Image::Size::Absolute.new(38, 38) } + let(:region) { IIIF::Image::Region::Absolute.new(200, 100, 100, 100) } - let(:image_info) { Riiif::ImageInformation.new(1000, 1000) } + let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute) @@ -60,8 +60,8 @@ end context 'and size is a width' do - let(:size) { Riiif::Size::Width.new(image_info, 651) } - let(:image_info) { Riiif::ImageInformation.new(1000, 1000) } + let(:size) { IIIF::Image::Size::Width.new(651) } + let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute) @@ -73,8 +73,8 @@ end context 'and size is a height' do - let(:size) { Riiif::Size::Height.new(image_info, 581) } - let(:image_info) { Riiif::ImageInformation.new(1000, 1000) } + let(:size) { IIIF::Image::Size::Height.new(581) } + let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute) @@ -90,7 +90,7 @@ let(:reduction_factor) { 1 } context 'and size is a Percent' do - let(:size) { Riiif::Size::Percent.new(image_info, 30.0) } + let(:size) { IIIF::Image::Size::Percent.new(30.0) } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute) @@ -102,8 +102,8 @@ end context 'and size is a width' do - let(:size) { Riiif::Size::Width.new(image_info, 408) } - let(:image_info) { Riiif::ImageInformation.new(1000, 1000) } + let(:size) { IIIF::Image::Size::Width.new(408) } + let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute) @@ -115,8 +115,8 @@ end context 'and size is a height' do - let(:size) { Riiif::Size::Height.new(image_info, 481) } - let(:image_info) { Riiif::ImageInformation.new(1000, 1000) } + let(:size) { IIIF::Image::Size::Height.new(481) } + let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute) @@ -129,7 +129,7 @@ end context 'when reduction_factor is 2' do - let(:size) { Riiif::Size::Percent.new(image_info, 20.0) } + let(:size) { IIIF::Image::Size::Percent.new(20.0) } let(:reduction_factor) { 2 } it 'calls the Imagemagick transform' do expect(Riiif::CommandRunner).to receive(:execute)