Skip to content

Commit

Permalink
feat: add vips rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
knarewski committed Nov 28, 2024
1 parent bdc3cea commit 5c8ddfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 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
6 changes: 3 additions & 3 deletions spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
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
Expand All @@ -120,7 +120,7 @@
end
end

context '180 degress', vips_wip: processor_name == 'vips' do
context '180 degress' do
let(:angle) { 180 }

it 'rotates the image' do
Expand All @@ -129,7 +129,7 @@
end
end

context '270 degress', vips_wip: processor_name == 'vips' do
context '270 degress' do
let(:angle) { 270 }

it 'rotates the image' do
Expand Down

0 comments on commit 5c8ddfb

Please sign in to comment.