Skip to content

Commit

Permalink
[minimagick] Move handling :define to #apply_options
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Apr 4, 2018
1 parent beeea21 commit 01223fa
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/image_processing/mini_magick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ def append(magick, *args)
magick.merge! args
end

def load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, define: {}, **options)
def load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **options)
if path_or_magick.is_a?(::MiniMagick::Tool)
magick = path_or_magick
else
source_path = path_or_magick
magick = ::MiniMagick::Tool::Convert.new

apply_define(magick, define)
apply_options(magick, options)

input_path = source_path
Expand All @@ -71,8 +70,7 @@ def load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, defi
magick
end

def save_image(magick, destination_path, define: {}, **options)
apply_define(magick, define)
def save_image(magick, destination_path, **options)
apply_options(magick, options)

magick << destination_path
Expand All @@ -95,6 +93,18 @@ def sharpen_value(parameters)
"#{radius}x#{sigma}"
end

def apply_options(magick, define: {}, **options)
options.each do |option, value|
case value
when true, nil then magick.send(option)
when false then magick.send(option).+
else magick.send(option, *value)
end
end

apply_define(magick, define)
end

def apply_define(magick, define)
define.each do |namespace, options|
namespace = namespace.to_s.gsub("_", "-")
Expand All @@ -107,16 +117,6 @@ def apply_define(magick, define)
end
end

def apply_options(magick, options)
options.each do |option, value|
case value
when true, nil then magick.send(option)
when false then magick.send(option).+
else magick.send(option, *value)
end
end
end

def prepend_args(magick, args)
magick.args.replace args + magick.args
magick
Expand Down

0 comments on commit 01223fa

Please sign in to comment.