diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aa777a..7a1c67f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Vips image processor (resizing) - Vips colour filters - Vips crop +- Vips rotate ### Removed - [BREAKING] dropped support for a broken 'dominant' border colour diff --git a/lib/morandi/vips_image_processor.rb b/lib/morandi/vips_image_processor.rb index fe7fbad..6b09993 100644 --- a/lib/morandi/vips_image_processor.rb +++ b/lib/morandi/vips_image_processor.rb @@ -60,6 +60,7 @@ def process! @scale = 1.0 end + apply_rotate! apply_crop! apply_filters! @@ -83,6 +84,23 @@ def write_to_jpeg(write_to, quality = nil) private + def angle + @options['angle'].to_i % 360 + end + + def apply_rotate! + @img = case angle + when 0 then @img + when 90 then @img.rot90 + when 180 then @img.rot180 + when 270 then @img.rot270 + else raise('"angle" option only accepts multiples of 90') + end + + @image_width = @img.width + @image_height = @img.height + end + def apply_crop! crop = @options['crop'] diff --git a/spec/fixtures/reference_images/vips/plasma-rotated-180.jpg b/spec/fixtures/reference_images/vips/plasma-rotated-180.jpg new file mode 100644 index 0000000..49a833c Binary files /dev/null and b/spec/fixtures/reference_images/vips/plasma-rotated-180.jpg differ diff --git a/spec/fixtures/reference_images/vips/plasma-rotated-270.jpg b/spec/fixtures/reference_images/vips/plasma-rotated-270.jpg new file mode 100644 index 0000000..962efbb Binary files /dev/null and b/spec/fixtures/reference_images/vips/plasma-rotated-270.jpg differ diff --git a/spec/fixtures/reference_images/vips/plasma-rotated-90.jpg b/spec/fixtures/reference_images/vips/plasma-rotated-90.jpg new file mode 100644 index 0000000..51bcad2 Binary files /dev/null and b/spec/fixtures/reference_images/vips/plasma-rotated-90.jpg differ diff --git a/spec/morandi_spec.rb b/spec/morandi_spec.rb index 2f39f70..a6fb63e 100644 --- a/spec/morandi_spec.rb +++ b/spec/morandi_spec.rb @@ -111,30 +111,30 @@ describe 'when given an angle of rotation' do let(:options) { { 'angle' => angle } } - context '90 degress', vips_wip: processor_name == 'vips' do + context '90 degress' do let(:angle) { 90 } it 'rotates the image' do process_image - expect(file_out).to match_reference_image('plasma-rotated-90') + expect(file_out).to match_reference_image(reference_image_prefix, 'plasma-rotated-90') end end - context '180 degress', vips_wip: processor_name == 'vips' do + context '180 degress' do let(:angle) { 180 } it 'rotates the image' do process_image - expect(file_out).to match_reference_image('plasma-rotated-180') + expect(file_out).to match_reference_image(reference_image_prefix, 'plasma-rotated-180') end end - context '270 degress', vips_wip: processor_name == 'vips' do + context '270 degress' do let(:angle) { 270 } it 'rotates the image' do process_image - expect(file_out).to match_reference_image('plasma-rotated-270') + expect(file_out).to match_reference_image(reference_image_prefix, 'plasma-rotated-270') end end