diff --git a/app/services/riiif/region/absolute.rb b/app/services/riiif/region/absolute.rb index d12a738..dc49cc8 100644 --- a/app/services/riiif/region/absolute.rb +++ b/app/services/riiif/region/absolute.rb @@ -4,12 +4,17 @@ module 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 [String] x + # @param [String] y + # @param [String] width + # @param [String] height def initialize(image_info, x, y, width, height) @image_info = image_info - @offset_x = x - @offset_y = y - @width = width - @height = height + @offset_x = x.to_i + @offset_y = y.to_i + @width = width.to_i + @height = height.to_i end attr_reader :width, :height diff --git a/app/services/riiif/size/absolute.rb b/app/services/riiif/size/absolute.rb index 80c4971..66321a4 100644 --- a/app/services/riiif/size/absolute.rb +++ b/app/services/riiif/size/absolute.rb @@ -4,10 +4,13 @@ module Size # 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 [String] width + # @param [String] height def initialize(info, width, height) @image_info = info - @width = width - @height = height + @width = width.to_i + @height = height.to_i end # @return [String] a resize directive for imagemagick to use diff --git a/spec/services/riiif/region/absolute_spec.rb b/spec/services/riiif/region/absolute_spec.rb new file mode 100644 index 0000000..19e3b9d --- /dev/null +++ b/spec/services/riiif/region/absolute_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +RSpec.describe Riiif::Region::Absolute do + let(:image_info) { double } + + context 'when initialized with strings' do + let(:instance) { described_class.new(image_info, '5', '15', '50', '100') } + + it 'casts height to an integer' do + expect(instance.height).to eq 100 + end + + it 'casts width to an integer' do + expect(instance.width).to eq 50 + end + end +end diff --git a/spec/services/riiif/size/absolute_spec.rb b/spec/services/riiif/size/absolute_spec.rb new file mode 100644 index 0000000..4c5ef03 --- /dev/null +++ b/spec/services/riiif/size/absolute_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +RSpec.describe Riiif::Size::Absolute do + let(:image_info) { double } + + context 'when initialized with strings' do + let(:instance) { described_class.new(image_info, '50', '100') } + + it 'casts height to an integer' do + expect(instance.height).to eq 100 + end + + it 'casts width to an integer' do + expect(instance.width).to eq 50 + end + end +end