Class: ImageProcessing::MiniMagick::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/image_processing/mini_magick.rb

Constant Summary collapse

IMAGE_CLASS =
::MiniMagick::Tool
TRANSPARENT =
"rgba(255,255,255,0.0)"

Instance Method Summary collapse

Instance Method Details

#append(magick, *args) ⇒ Object



56
57
58
# File 'lib/image_processing/mini_magick.rb', line 56

def append(magick, *args)
  magick.merge! args
end

#apply_operation(name, magick, *args) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/image_processing/mini_magick.rb', line 24

def apply_operation(name, magick, *args)
  if respond_to?(name)
    public_send(name, magick, *args)
  else
    magick.send(name, *args)
  end
end

#load_image(path_or_magick, page: nil, geometry: nil, fail: true, auto_orient: true) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/image_processing/mini_magick.rb', line 60

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

    input_path  = source_path
    input_path += "[#{page}]" if page
    input_path += "[#{geometry}]" if geometry

    magick << input_path
  end

  magick.regard_warnings if fail
  magick.auto_orient if auto_orient

  magick
end

#resize_and_pad(magick, width, height, background: TRANSPARENT, gravity: "Center") ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/image_processing/mini_magick.rb', line 47

def resize_and_pad(magick, width, height, background: TRANSPARENT, gravity: "Center")
  background = TRANSPARENT if background == "transparent"

  magick.resize "#{width}x#{height}"
  magick.background background
  magick.gravity gravity
  magick.extent "#{width}x#{height}"
end

#resize_to_fill(magick, width, height, gravity: "Center") ⇒ Object



40
41
42
43
44
45
# File 'lib/image_processing/mini_magick.rb', line 40

def resize_to_fill(magick, width, height, gravity: "Center")
  magick.resize "#{width}x#{height}^"
  magick.gravity gravity
  magick.background TRANSPARENT
  magick.extent "#{width}x#{height}"
end

#resize_to_fit(magick, width, height) ⇒ Object



36
37
38
# File 'lib/image_processing/mini_magick.rb', line 36

def resize_to_fit(magick, width, height)
  magick.resize "#{width}x#{height}"
end

#resize_to_limit(magick, width, height) ⇒ Object



32
33
34
# File 'lib/image_processing/mini_magick.rb', line 32

def resize_to_limit(magick, width, height)
  magick.resize "#{width}x#{height}>"
end

#save_image(magick, destination_path, **options) ⇒ Object



80
81
82
83
# File 'lib/image_processing/mini_magick.rb', line 80

def save_image(magick, destination_path, **options)
  magick << destination_path
  magick.call
end