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
-
#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, **options) ⇒ Object
Methods inherited from Processor
#apply_operation, #custom, #initialize
Instance Method Details
#append(magick, *args) ⇒ Object
49
50
51
|
# File 'lib/image_processing/mini_magick.rb', line 49
def append(magick, *args)
magick.merge! args
end
|
#limits(magick, options) ⇒ Object
44
45
46
47
|
# File 'lib/image_processing/mini_magick.rb', line 44
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/image_processing/mini_magick.rb', line 53
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
35
36
37
38
39
40
41
42
|
# File 'lib/image_processing/mini_magick.rb', line 35
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
28
29
30
31
32
33
|
# File 'lib/image_processing/mini_magick.rb', line 28
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
24
25
26
|
# File 'lib/image_processing/mini_magick.rb', line 24
def resize_to_fit(magick, width, height, **options)
thumbnail(magick, "#{width}x#{height}", **options)
end
|
#resize_to_limit(magick, width, height, **options) ⇒ Object
20
21
22
|
# File 'lib/image_processing/mini_magick.rb', line 20
def resize_to_limit(magick, width, height, **options)
thumbnail(magick, "#{width}x#{height}>", **options)
end
|
#save_image(magick, destination_path, **options) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/image_processing/mini_magick.rb', line 73
def save_image(magick, destination_path, **options)
apply_options(magick, options)
magick << destination_path
magick.call
end
|