Class: Miso::Processor::ImageMagick

Inherits:
Miso::Processor show all
Includes:
Executioner
Defined in:
lib/miso/processor/image_magick.rb

Direct Known Subclasses

GraphicsMagick

Instance Attribute Summary

Attributes inherited from Miso::Processor

#input_file

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Miso::Processor

#height, #initialize, #width

Constructor Details

This class inherits a constructor from Miso::Processor

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/miso/processor/image_magick.rb', line 12

def self.available?
  !find_executable('convert').nil?
end

Instance Method Details

#_convertObject



45
# File 'lib/miso/processor/image_magick.rb', line 45

alias_method :_convert, :convert

#auto_orientObject



25
26
27
# File 'lib/miso/processor/image_magick.rb', line 25

def auto_orient
  operations << "-auto-orient"
end

#convert(source_path, output_path, options) ⇒ Object



46
47
48
49
# File 'lib/miso/processor/image_magick.rb', line 46

def convert(source_path, output_path, options)
  ensure_output_directory(output_path)
  _convert "'#{source_path}' #{options} '#{output_path}'"
end

#crop(width, height) ⇒ Object



16
17
18
19
# File 'lib/miso/processor/image_magick.rb', line 16

def crop(width, height)
  dimensions = "#{width}x#{height}"
  operations << "-resize #{dimensions}^ -gravity center -crop #{dimensions}+0+0!"
end

#dimensionsObject



29
30
31
32
33
# File 'lib/miso/processor/image_magick.rb', line 29

def dimensions
  if info = identify(input_file) and match = /\s(\d+)x(\d+)\+/.match(info)
    match.to_a[1..2].map { |d| d.to_i }
  end
end

#fit(width, height) ⇒ Object



21
22
23
# File 'lib/miso/processor/image_magick.rb', line 21

def fit(width, height)
  operations << "-resize #{width}x#{height}"
end

#write(output_file) ⇒ Object



35
36
37
38
39
# File 'lib/miso/processor/image_magick.rb', line 35

def write(output_file)
  options = operations.join(' ')
  operations.clear
  convert(input_file, output_file, options)
end