Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add vips rotate #38

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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