Skip to content

Commit

Permalink
feat: add vips rotate
Browse files Browse the repository at this point in the history
Reference images diffs:
- plasma-rotated-90 - MAE (Mean Average Error): 0.00802462
- plasma-rotated-180 - MAE: 0.0080234
- plasma-rotated-270 - MAE: 0.00750394
  • Loading branch information
knarewski committed Dec 2, 2024
1 parent cd0797e commit c38b981
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions lib/morandi/vips_image_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def process!
@scale = 1.0
end

apply_rotate!
apply_crop!
apply_filters!

Expand All @@ -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']

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c38b981

Please sign in to comment.