Class: Filemagic::CustomProcessors

Inherits:
Refile::MiniMagick
  • Object
show all
Defined in:
lib/filemagic/engine.rb

Instance Method Summary collapse

Instance Method Details

#call(file, *args, format: nil, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/filemagic/engine.rb', line 27

def call(file, *args, format: nil, &block)
  img = ::MiniMagick::Image.new(file.path)
  img.format(format.to_s.downcase, nil) if format
  send(@method, img, *args, &block)

  ::File.open(img.path, "rb")
end

#reposition(img, width, height, offset_x = '+0', offset_y = '+0') ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/filemagic/engine.rb', line 17

def reposition(img, width, height, offset_x = '+0', offset_y = '+0')
  ::MiniMagick::Tool::Convert.new do |cmd|
    yield cmd if block_given?
    cmd.resize "#{width}x"
    cmd.gravity "NorthWest"
    cmd.crop "#{width}x#{height}#{offset_x}#{formatted_offset(offset_y)}"
    cmd.merge! [img.path, img.path]
  end
end