Skip to content

Commit

Permalink
Use ImageProcessing::Builder#apply
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Apr 5, 2018
1 parent 3ba83f9 commit 4a64df3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion carrierwave.gemspec
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency "activesupport", ">= 4.0.0"
s.add_dependency "activemodel", ">= 4.0.0"
s.add_dependency "mime-types", ">= 1.16"
s.add_dependency "image_processing", "~> 1.0"
s.add_dependency "image_processing", "~> 1.1"
if RUBY_ENGINE == 'jruby'
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
else
Expand Down
25 changes: 9 additions & 16 deletions lib/carrierwave/processing/mini_magick.rb
Expand Up @@ -125,8 +125,9 @@ def convert(format, page=nil, &block)
def resize_to_limit(width, height, combine_options: {}, &block)
width, height = resolve_dimensions(width, height)

minimagick!(block, combine_options) do |builder|
minimagick!(block) do |builder|
builder.resize_to_limit(width, height)
.apply(combine_options)
end
end

Expand All @@ -148,8 +149,9 @@ def resize_to_limit(width, height, combine_options: {}, &block)
def resize_to_fit(width, height, combine_options: {}, &block)
width, height = resolve_dimensions(width, height)

minimagick!(block, combine_options) do |builder|
minimagick!(block) do |builder|
builder.resize_to_fit(width, height)
.apply(combine_options)
end
end

Expand All @@ -172,8 +174,9 @@ def resize_to_fit(width, height, combine_options: {}, &block)
def resize_to_fill(width, height, gravity = 'Center', combine_options: {}, &block)
width, height = resolve_dimensions(width, height)

minimagick!(block, combine_options) do |builder|
minimagick!(block) do |builder|
builder.resize_to_fill(width, height, gravity: gravity)
.apply(combine_options)
end
end

Expand Down Expand Up @@ -201,8 +204,9 @@ def resize_to_fill(width, height, gravity = 'Center', combine_options: {}, &bloc
def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {}, &block)
width, height = resolve_dimensions(width, height)

minimagick!(block, combine_options) do |builder|
minimagick!(block) do |builder|
builder.resize_and_pad(width, height, background: background, gravity: gravity)
.apply(combine_options)
end
end

Expand Down Expand Up @@ -284,10 +288,9 @@ def manipulate!
# === Raises
#
# [CarrierWave::ProcessingError] if processing failed.
def minimagick!(block = nil, **combine_options)
def minimagick!(block = nil)
builder = ImageProcessing::MiniMagick.source(current_path)
builder = yield(builder)
builder = append_combine_options(builder, combine_options)

result = builder.call
result.close
Expand All @@ -313,16 +316,6 @@ def minimagick!(block = nil, **combine_options)

private

def append_combine_options(builder, combine_options)
combine_options.inject(builder) do |builder, (option, value)|
if value.nil?
builder.send(option)
else
builder.send(option, *value)
end
end
end

def resolve_dimensions(*dimensions)
dimensions.map do |value|
next value unless value.instance_of?(Proc)
Expand Down

0 comments on commit 4a64df3

Please sign in to comment.