Class: ImageProcessing::MiniMagick::Processor
- Inherits:
-
Processor
- Object
- Processor
- ImageProcessing::MiniMagick::Processor
show all
- Defined in:
- lib/image_processing/mini_magick.rb
Constant Summary
collapse
- IMAGE_CLASS =
::MiniMagick::Tool
- SHARPEN_PARAMETERS =
{ radius: 0, sigma: 1 }
Instance Method Summary
collapse
-
#append(magick, *args) ⇒ Object
-
#define(magick, options) ⇒ Object
-
#limits(magick, options) ⇒ Object
-
#load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **options) ⇒ Object
-
#resize_and_pad(magick, width, height, background: :transparent, gravity: "Center", **options) ⇒ Object
-
#resize_to_fill(magick, width, height, gravity: "Center", **options) ⇒ Object
-
#resize_to_fit(magick, width, height, **options) ⇒ Object
-
#resize_to_limit(magick, width, height, **options) ⇒ Object
-
#save_image(magick, destination_path, allow_splitting: false, **options) ⇒ Object
Methods inherited from Processor
#apply_operation, #custom, #initialize
Instance Method Details
#append(magick, *args) ⇒ Object
67
68
69
|
# File 'lib/image_processing/mini_magick.rb', line 67
def append(magick, *args)
magick.merge! args
end
|
#define(magick, options) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/image_processing/mini_magick.rb', line 46
def define(magick, options)
return magick.define(options) if options.is_a?(String)
options.each do |namespace, options|
namespace = namespace.to_s.gsub("_", "-")
options.each do |key, value|
key = key.to_s.gsub("_", "-")
magick.define "#{namespace}:#{key}=#{value}"
end
end
magick
end
|
#limits(magick, options) ⇒ Object
62
63
64
65
|
# File 'lib/image_processing/mini_magick.rb', line 62
def limits(magick, options)
limit_args = options.flat_map { |type, value| %W[-limit #{type} #{value}] }
prepend_args(magick, limit_args)
end
|
#load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **options) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/image_processing/mini_magick.rb', line 71
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_options(magick, options)
input_path = source_path
input_path += "[#{page}]" if page
input_path += "[#{geometry}]" if geometry
magick << input_path
end
magick.auto_orient if auto_orient
magick
end
|
#resize_and_pad(magick, width, height, background: :transparent, gravity: "Center", **options) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/image_processing/mini_magick.rb', line 37
def resize_and_pad(magick, width, height, background: :transparent, gravity: "Center", **options)
background = "rgba(255,255,255,0.0)" if background.to_s == "transparent"
thumbnail(magick, "#{width}x#{height}", **options)
magick.background background
magick.gravity gravity
magick.extent "#{width}x#{height}"
end
|
#resize_to_fill(magick, width, height, gravity: "Center", **options) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/image_processing/mini_magick.rb', line 30
def resize_to_fill(magick, width, height, gravity: "Center", **options)
thumbnail(magick, "#{width}x#{height}^", **options)
magick.gravity gravity
magick.background "rgba(255,255,255,0.0)" magick.extent "#{width}x#{height}"
end
|
#resize_to_fit(magick, width, height, **options) ⇒ Object
26
27
28
|
# File 'lib/image_processing/mini_magick.rb', line 26
def resize_to_fit(magick, width, height, **options)
thumbnail(magick, "#{width}x#{height}", **options)
end
|
#resize_to_limit(magick, width, height, **options) ⇒ Object
22
23
24
|
# File 'lib/image_processing/mini_magick.rb', line 22
def resize_to_limit(magick, width, height, **options)
thumbnail(magick, "#{width}x#{height}>", **options)
end
|
#save_image(magick, destination_path, allow_splitting: false, **options) ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/image_processing/mini_magick.rb', line 91
def save_image(magick, destination_path, allow_splitting: false, **options)
apply_options(magick, options)
magick << destination_path
magick.call
disallow_split_layers!(destination_path) unless allow_splitting
end
|