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 gamma support to vips image processor #41

Merged
merged 2 commits into from
Dec 9, 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 @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Vips crop
- Vips rotate
- Vips straighten
- Vips gamma

### Removed
- [BREAKING] dropped support for a broken 'dominant' border colour
Expand Down
3 changes: 2 additions & 1 deletion lib/morandi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ module Morandi
# @option options [Float] 'gamma' Gamma correct image
# @option options [Integer] 'contrast' Change image contrast (-20..20)
# @option options [Integer] 'sharpen' Sharpen (1..5) / Blur (-1..-5)
# @option options [Integer] 'straighten' Rotate by a small angle (in degrees) and zoom in to fill the size
# @option options [Array[[Integer,Integer],...]] 'redeye' Apply redeye correction at point
# @option options [Integer] 'angle' Rotate image clockwise by multiple of 90 (0, 90, 180, 270)
# @option options [Integer] 'angle' Rotate image clockwise by multiple of 90 degrees (0, 90, 180, 270)
# @option options [Array[Integer,Integer,Integer,Integer]] 'crop' Crop image (x, y, width, height)
# @option options [String] 'fx' Apply colour filters ('greyscale', 'sepia', 'bluetone')
# @option options [String] 'border-style' Set border style ('square', 'retro')
Expand Down
7 changes: 7 additions & 0 deletions lib/morandi/vips_image_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def process!
@scale = 1.0
end

apply_gamma!
apply_rotate!
apply_crop!
apply_filters!
Expand All @@ -87,6 +88,12 @@ def write_to_jpeg(target_path, quality = nil)

private

def apply_gamma!
return unless @options['gamma'] && not_equal_to_one(@options['gamma'])

@img = @img.gamma(exponent: @options['gamma'])
end

def angle
@options['angle'].to_i % 360
end
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions spec/morandi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
end
end

context 'when given a gamma option', vips_wip: processor_name == 'vips' do
context 'when given a gamma option' do
let(:options) { { 'gamma' => 2.0 } }

it 'should apply the gamma to the image' do
Expand All @@ -288,7 +288,7 @@
expect(File).to exist(file_out)
expect(processed_image_type).to eq('jpeg')

expect(file_out).to match_reference_image('plasma-gamma')
expect(file_out).to match_reference_image(reference_image_prefix, 'plasma-gamma')
end
end

Expand Down
Loading