Class: ImageProcessing::MiniMagick::Processor

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

Constant Summary collapse

IMAGE_CLASS =
::MiniMagick::Tool

Instance Method Summary collapse

Methods inherited from Processor

#apply_operation, #custom, #initialize

Constructor Details

This class inherits a constructor from ImageProcessing::Processor

Instance Method Details

#append(magick, *args) ⇒ Object



53
54
55
# File 'lib/image_processing/mini_magick.rb', line 53

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

#limits(magick, options) ⇒ Object



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

def limits(magick, options)
  limit_args = options.flat_map { |type, value| %W[-limit #{type} #{value}] }
  magick.args.replace limit_args + magick.args
  magick
end

#load_image(path_or_magick, page: nil, geometry: nil, fail: true, auto_orient: true, define: {}, **options) ⇒ Object



57
58
59
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 57

def load_image(path_or_magick, page: nil, geometry: nil, fail: true, auto_orient: true, define: {}, **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
    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



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

def resize_and_pad(magick, width, height, background: :transparent, gravity: "Center")
  background = "rgba(255,255,255,0.0)" if background.to_s == "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



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

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

#resize_to_fit(magick, width, height) ⇒ Object



27
28
29
# File 'lib/image_processing/mini_magick.rb', line 27

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

#resize_to_limit(magick, width, height) ⇒ Object



23
24
25
# File 'lib/image_processing/mini_magick.rb', line 23

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

#save_image(magick, destination_path, define: {}, **options) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/image_processing/mini_magick.rb', line 80

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

  magick << destination_path

  magick.call
end