diff --git a/Gemfile.lock b/Gemfile.lock index a577a79..2d288c1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,7 +10,7 @@ GIT PATH remote: . specs: - carrierwave-vips (1.1.2) + carrierwave-vips (1.1.3) carrierwave (>= 0.11.0) ruby-vips (~> 1.0, >= 1.0.2) diff --git a/README.md b/README.md index 9028d8e..f0b72db 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,25 @@ You can use the following methods to change your images. To see how vips stands up to other image processing libraries, see this benchmark: https://github.com/stanislaw/carrierwave-vips-benchmarks +Configuration +------------- + +When reducing the size of images, a sharpening mask is used. To change or disable this behavior: + +``` +CarrierWave::Vips.configure do |c| + c.sharpen_mask = false # Disable sharpening mask on image reduction + c.sharpen_mask = [ # Default mask + [ -1, -1, -1 ], + [ -1, 24, -1 ], + [ -1, -1, -1 ] + ] + c.sharpen_scale = 16 +end +``` + +See VIPS::Image.new_from_array for more information on what these two do. + Special considerations ---------------------- diff --git a/carrierwave-vips.gemspec b/carrierwave-vips.gemspec index 07bcffd..44b4940 100644 --- a/carrierwave-vips.gemspec +++ b/carrierwave-vips.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'carrierwave-vips' - s.version = '1.1.2' - s.date = '2016-09-06' + s.version = '1.1.3' + s.date = '2016-10-26' s.summary = "Adds VIPS support to CarrierWave" s.description = "Adds VIPS support to CarrierWave" s.authors = ["Jeremy Nicoll"] diff --git a/lib/carrierwave/vips.rb b/lib/carrierwave/vips.rb index 33fa889..4ec2a53 100644 --- a/lib/carrierwave/vips.rb +++ b/lib/carrierwave/vips.rb @@ -3,13 +3,16 @@ module CarrierWave module Vips - SHARPEN_MASK = begin - conv_mask = [ - [ -1, -1, -1 ], - [ -1, 24, -1 ], - [ -1, -1, -1 ] - ] - ::Vips::Image.new_from_array conv_mask, 16 + def self.configure + @config ||= begin + c = Struct.new(:sharpen_mask, :sharpen_scale).new + c.sharpen_mask = [ [ -1, -1, -1 ], [ -1, 24, -1 ], [ -1, -1, -1 ] ] + c.sharpen_scale = 16 + c + end + @config + yield @config if block_given? + @config end def self.included(base) @@ -256,7 +259,7 @@ def resize_image(image, width, height, min_or_max = :min) image = image.resize(ratio, kernel: :nearest) else image = image.resize(ratio, kernel: :cubic) - image = image.conv SHARPEN_MASK + image = image.conv(cwv_sharpen_mask) if cwv_config.sharpen_mask end image end @@ -284,5 +287,13 @@ def ext(path) matches && matches[1].downcase end + def cwv_config + CarrierWave::Vips.configure + end + + def cwv_sharpen_mask(mask = cwv_config.sharpen_mask, scale = cwv_config.sharpen_scale) + ::Vips::Image.new_from_array(mask, scale) + end + end # Vips end # CarrierWave