diff --git a/CHANGELOG.md b/CHANGELOG.md index ff003d7..22b4863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/morandi.rb b/lib/morandi.rb index fc6eeec..0bebc18 100644 --- a/lib/morandi.rb +++ b/lib/morandi.rb @@ -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') diff --git a/lib/morandi/vips_image_processor.rb b/lib/morandi/vips_image_processor.rb index 226e33f..373a50b 100644 --- a/lib/morandi/vips_image_processor.rb +++ b/lib/morandi/vips_image_processor.rb @@ -61,6 +61,7 @@ def process! @scale = 1.0 end + apply_gamma! apply_rotate! apply_crop! apply_filters! @@ -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 diff --git a/spec/fixtures/reference_images/vips/plasma-gamma.jpg b/spec/fixtures/reference_images/vips/plasma-gamma.jpg new file mode 100644 index 0000000..2c420c0 Binary files /dev/null and b/spec/fixtures/reference_images/vips/plasma-gamma.jpg differ diff --git a/spec/morandi_spec.rb b/spec/morandi_spec.rb index b5a12e2..cbe5039 100644 --- a/spec/morandi_spec.rb +++ b/spec/morandi_spec.rb @@ -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 @@ -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