class MiniMagick::Tool
end
mogrify << “path/to/image.jpg”
mogrify.resize “500x500”
MiniMagick.mogrify do |mogrify|
@example
which is more high-level.
Class that wraps command-line tools directly, as opposed MiniMagick::Image
#
def self.new(name, **options)
-
(MiniMagick::Tool, String)- If no block is given, returns an
def self.new(name, **options) instance = super if block_given? yield instance instance.call else instance end end
def +(*values)
-
(self)-
def +(*values) args[-1] = args[-1].sub(/^-/, '+') self.merge!(values) self end
def <<(arg)
-
(self)-
def <<(arg) args << arg.to_s self end
def call(**options)
-
(String)- Returns the output of the command
Other tags:
- Yield: - Optionally yields stdout, stderr, and exit status
def call(**options) options = @options.merge(options) options[:warnings] = false if block_given? shell = MiniMagick::Shell.new stdout, stderr, status = shell.run(command, **options) yield stdout, stderr, status if block_given? stdout.chomp("\n") end
def clone(*args)
so we need to override it so that it correctly acts as an option method.
This option is a valid ImageMagick option, but it's also a Ruby method,
#
def clone(*args) self << '-clone' self.merge!(args) self end
def command
-
(Array-)
def command [*executable, *args] end
def executable
-
(Array-)
def executable exe = Array(MiniMagick.cli_prefix).dup exe << "magick" if MiniMagick.imagemagick7? && name != "magick" exe << "gm" if MiniMagick.graphicsmagick exe << name end
def initialize(name, **options)
(**options)-
:stdin(String) -- Content to send to standard input stream. -
:warnings(Boolean) -- Whether to print warnings to stderrr. -
:errors(Boolean) -- Whether to raise errors on non-zero
Parameters:
-
options(Hash) -- -
name(String) --
def initialize(name, **options) @name = name @args = [] @options = options end
def merge!(new_args)
-
(self)-
def merge!(new_args) new_args.each { |arg| self << arg } self end
def method_missing(name, *args)
mogrify.command.join(" ") # => "mogrify -adaptive-blur ... -foo-bar"
mogrify.foo_bar
mogrify.adaptive_blur("...")
mogrify = MiniMagick::Tool.new("mogrify")
@example
Any undefined method will be transformed into a CLI option
#
def method_missing(name, *args) option = "-#{name.to_s.tr('_', '-')}" self << option self.merge!(args) self end
def stack(*args)
# executes `convert wand.gif \( wizard.gif -rotate 30 \) +append images.gif`
end
convert << "images.gif"
convert.append.+
end
stack.rotate(30)
stack << "wand.gif"
convert.stack do |stack|
convert << "wand.gif"
MiniMagick.convert do |convert|
@example
Create an ImageMagick stack in the command (surround.
#
def stack(*args) self << "(" args.each do |value| case value when Hash then value.each { |key, value| send(key, *value) } when String then self << value end end yield self if block_given? self << ")" end
def stdin
# executes `identify -` with the given standard input
identify.call(stdin: image_content)
identify.stdin
identify = MiniMagick.identify
@example
Adds ImageMagick's pseudo-filename `-` for standard input.
#
def stdin self << "-" end
def stdout
# executes `convert input.jpg -auto-orient -` which returns file contents
end
convert.stdout
convert.auto_orient
convert << "input.jpg"
content = MiniMagick.convert do |convert|
@example
Adds ImageMagick's pseudo-filename `-` for standard output.
#
def stdout self << "-" end