class Filemagic::CustomProcessors

Public Instance Methods

call(file, *args, format: nil, &block) click to toggle source
# 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') { |cmd| ... } click to toggle source
# 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

Private Instance Methods

formatted_offset(value) click to toggle source
# File lib/filemagic/engine.rb, line 36
def formatted_offset(value)
  int_to_sign_string(-1 * value.to_i)
end
int_to_sign_string(value) click to toggle source
# File lib/filemagic/engine.rb, line 40
def int_to_sign_string(value)
  sprintf("%+d", value)
end