Class MiniMagick::Tool
In: lib/mini_magick/tool/composite.rb
lib/mini_magick/tool/conjure.rb
lib/mini_magick/tool/compare.rb
lib/mini_magick/tool/stream.rb
lib/mini_magick/tool/mogrify_restricted.rb
lib/mini_magick/tool/display.rb
lib/mini_magick/tool/mogrify.rb
lib/mini_magick/tool/montage.rb
lib/mini_magick/tool/convert.rb
lib/mini_magick/tool/identify.rb
lib/mini_magick/tool/magick.rb
lib/mini_magick/tool/import.rb
lib/mini_magick/tool/animate.rb
lib/mini_magick/tool.rb
Parent: Object

Abstract class that wraps command-line tools. It shouldn‘t be used directly, but through one of its subclasses (e.g. {MiniMagick::Tool::Mogrify}). Use this class if you want to be closer to the metal and execute ImageMagick commands directly, but still with a nice Ruby interface.

@example

  MiniMagick::Tool::Mogrify.new do |builder|
    builder.resize "500x500"
    builder << "path/to/image.jpg"
  end

Methods

+   <<   call   clone   command   executable   merge!   method_missing   new   new   option_methods   stack   stdin   stdout  

Classes and Modules

Class MiniMagick::Tool::Animate
Class MiniMagick::Tool::Compare
Class MiniMagick::Tool::Composite
Class MiniMagick::Tool::Conjure
Class MiniMagick::Tool::Convert
Class MiniMagick::Tool::Display
Class MiniMagick::Tool::Identify
Class MiniMagick::Tool::Import
Class MiniMagick::Tool::Magick
Class MiniMagick::Tool::Mogrify
Class MiniMagick::Tool::MogrifyRestricted
Class MiniMagick::Tool::Montage
Class MiniMagick::Tool::Stream

Constants

CREATION_OPERATORS = %w[xc canvas logo rose gradient radial-gradient plasma pattern text pango]

Attributes

args  [R]  @private
name  [R]  @private

Public Class methods

Aside from classic instantiation, it also accepts a block, and then executes the command in the end.

@example

  version = MiniMagick::Tool::Identify.new { |b| b.version }
  puts version

@return [MiniMagick::Tool, String] If no block is given, returns an

  instance of the tool, if block is given, returns the output of the
  command.

@param whiny [Boolean] Whether to raise errors on exit codes different

  than 0.

@example

  MiniMagick::Tool::Identify.new(whiny: false) do |identify|
    identify.help # returns exit status 1, which would otherwise throw an error
  end

Public Instance methods

Changes the last operator to its "plus" form.

@example

  MiniMagick::Tool::Mogrify.new do |mogrify|
    mogrify.antialias.+
    mogrify.distort.+("Perspective", "0,0,4,5 89,0,45,46")
  end
  # executes `mogrify +antialias +distort Perspective '0,0,4,5 89,0,45,46'`

@return [self]

Appends raw options, useful for appending image paths.

@return [self]

Executes the command that has been built up.

@example

  mogrify = MiniMagick::Tool::Mogrify.new
  mogrify.resize("500x500")
  mogrify << "path/to/image.jpg"
  mogrify.call # executes `mogrify -resize 500x500 path/to/image.jpg`

@example

  mogrify = MiniMagick::Tool::Mogrify.new
  # build the command
  mogrify.call do |stdout, stderr, status|
    # ...
  end

@yield [Array] Optionally yields stdout, stderr, and exit status

@return [String] Returns the output of the command

This option is a valid ImageMagick option, but it‘s also a Ruby method, so we need to override it so that it correctly acts as an option method.

The currently built-up command.

@return [Array<String>]

@example

  mogrify = MiniMagick::Tool::Mogrify.new
  mogrify.resize "500x500"
  mogrify.contrast
  mogrify.command #=> ["mogrify", "-resize", "500x500", "-contrast"]

The executable used for this tool. Respects {MiniMagick::Configuration#cli}, {MiniMagick::Configuration#cli_path}, and {MiniMagick::Configuration#cli_prefix}.

@return [Array<String>]

@example

  MiniMagick.configure { |config| config.cli = :graphicsmagick }
  identify = MiniMagick::Tool::Identify.new
  identify.executable #=> ["gm", "identify"]

@example

  MiniMagick.configure do |config|
    config.cli = :graphicsmagick
    config.cli_prefix = ['firejail', '--force']
  end
  identify = MiniMagick::Tool::Identify.new
  identify.executable #=> ["firejail", "--force", "gm", "identify"]

Merges a list of raw options.

@return [self]

Any undefined method will be transformed into a CLI option

  mogrify = MiniMagick::Tool.new("mogrify")
  mogrify.adaptive_blur("...")
  mogrify.foo_bar
  mogrify.command.join(" ") "mogrify -adaptive-blur ... -foo-bar"

Create an ImageMagick stack in the command (surround.

@example

  MiniMagick::Tool::Convert.new do |convert|
    convert << "wand.gif"
    convert.stack do |stack|
      stack << "wand.gif"
      stack.rotate(30)
    end
    convert.append.+
    convert << "images.gif"
  end
  # executes `convert wand.gif \( wizard.gif -rotate 30 \) +append images.gif`

Adds ImageMagick‘s pseudo-filename `-` for standard input.

@example

  identify = MiniMagick::Tool::Identify.new
  identify.stdin
  identify.call(stdin: image_content)
  # executes `identify -` with the given standard input

Adds ImageMagick‘s pseudo-filename `-` for standard output.

@example

  content = MiniMagick::Tool::Convert.new do |convert|
    convert << "input.jpg"
    convert.auto_orient
    convert.stdout
  end
  # executes `convert input.jpg -auto-orient -` which returns file contents

[Validate]