module MiniMagick::Configuration

Constants

CLI_DETECTION

Attributes

cli_path[W]

If you don't have the CLI tools in your PATH, you can set the path to the executables.

cli_prefix[RW]

Adds a prefix to the CLI command. For example, you could use `firejail` to run all commands in a sandbox. Can be a string, or an array of strings. e.g. 'firejail', or ['firejail', '–force']

@return [String] @return [Array<String>]

debug[R]

When get to `true`, it outputs each command to STDOUT in their shell version.

@return [Boolean]

logger[RW]

Logger for {#debug}, default is `MiniMagick::Logger.new(STDOUT)`, but you can override it, for example if you want the logs to be written to a file.

@return [Logger]

processor_path[RW]

@private (for backwards compatibility)

shell_api[RW]

Instructs MiniMagick how to execute the shell commands. Available APIs are “open3” (default) and “posix-spawn” (requires the “posix-spawn” gem).

@return [String]

timeout[RW]

If you don't want commands to take too long, you can set a timeout (in seconds).

@return [Integer]

validate_on_create[RW]

If set to `true`, it will `identify` every newly created image, and raise `MiniMagick::Invalid` if the image is not valid. Useful for validating user input, although it adds a bit of overhead. Defaults to `true`.

@return [Boolean]

validate_on_write[RW]

If set to `true`, it will `identify` every image that gets written (with {MiniMagick::Image#write}), and raise `MiniMagick::Invalid` if the image is not valid. Useful for validating that processing was sucessful, although it adds a bit of overhead. Defaults to `true`.

@return [Boolean]

whiny[RW]

If set to `false`, it will not raise errors when ImageMagick returns status code different than 0. Defaults to `true`.

@return [Boolean]

Public Class Methods

extended(base) click to toggle source
# File lib/mini_magick/configuration.rb, line 84
def self.extended(base)
  base.validate_on_create = true
  base.validate_on_write = true
  base.whiny = true
  base.shell_api = "open3"
  base.logger = Logger.new($stdout).tap { |l| l.level = Logger::INFO }
end

Public Instance Methods

cli() click to toggle source

Get [ImageMagick](www.imagemagick.org) or [GraphicsMagick](www.graphicsmagick.org).

@return [Symbol] `:imagemagick` or `:graphicsmagick`

# File lib/mini_magick/configuration.rb, line 134
def cli
  if instance_variable_defined?("@cli")
    instance_variable_get("@cli")
  else
    cli = CLI_DETECTION.key(processor) or
      fail MiniMagick::Error, "You must have ImageMagick or GraphicsMagick installed"

    instance_variable_set("@cli", cli)
  end
end
cli=(value) click to toggle source

Set whether you want to use [ImageMagick](www.imagemagick.org) or [GraphicsMagick](www.graphicsmagick.org).

# File lib/mini_magick/configuration.rb, line 149
def cli=(value)
  @cli = value

  if not CLI_DETECTION.key?(@cli)
    raise ArgumentError,
      "CLI has to be set to either :imagemagick, :imagemagick7 or :graphicsmagick" \
      ", was set to #{@cli.inspect}"
  end
end
cli_path() click to toggle source

If you set the path of CLI tools, you can get the path of the executables.

@return [String]

# File lib/mini_magick/configuration.rb, line 165
def cli_path
  if instance_variable_defined?("@cli_path")
    instance_variable_get("@cli_path")
  else
    processor_path = instance_variable_get("@processor_path") if instance_variable_defined?("@processor_path")

    instance_variable_set("@cli_path", processor_path)
  end
end
configure() { |self| ... } click to toggle source

@yield [self] @example

MiniMagick.configure do |config|
  config.cli = :graphicsmagick
  config.timeout = 5
end
# File lib/mini_magick/configuration.rb, line 100
def configure
  yield self
end
debug=(value) click to toggle source

When set to `true`, it outputs each command to STDOUT in their shell version.

# File lib/mini_magick/configuration.rb, line 179
def debug=(value)
  warn "MiniMagick.debug is deprecated and will be removed in MiniMagick 5. Use `MiniMagick.logger.level = Logger::DEBUG` instead."
  logger.level = value ? Logger::DEBUG : Logger::INFO
end
processor() click to toggle source

@private (for backwards compatibility)

# File lib/mini_magick/configuration.rb, line 111
def processor
  @processor ||= CLI_DETECTION.values.detect do |processor|
    MiniMagick::Utilities.which(processor)
  end
end
processor=(processor) click to toggle source

@private (for backwards compatibility)

# File lib/mini_magick/configuration.rb, line 118
def processor=(processor)
  @processor = processor.to_s

  unless CLI_DETECTION.value?(@processor)
    raise ArgumentError,
      "processor has to be set to either \"magick\", \"mogrify\" or \"gm\"" \
      ", was set to #{@processor.inspect}"
  end
end
reload_tools() click to toggle source

Backwards compatibility

# File lib/mini_magick/configuration.rb, line 185
def reload_tools
  warn "MiniMagick.reload_tools is deprecated because it is no longer necessary"
end