Module: MiniMagick::Configuration

Included in:
MiniMagick
Defined in:
lib/mini_magick/configuration.rb

Constant Summary collapse

CLI_DETECTION =
{
  imagemagick:    "mogrify",
  graphicsmagick: "gm",
  imagemagick7:   "magick",
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cliSymbol

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

Returns:

  • (Symbol)

    ‘:imagemagick`, `:imagemagick7`, or `:graphicsmagick`



13
14
15
# File 'lib/mini_magick/configuration.rb', line 13

def cli
  @cli
end

#cli_pathString

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

Returns:

  • (String)


23
24
25
# File 'lib/mini_magick/configuration.rb', line 23

def cli_path
  @cli_path
end

#cli_prefixString+

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’]

Returns:

  • (String)
  • (Array<String>)


36
37
38
# File 'lib/mini_magick/configuration.rb', line 36

def cli_prefix
  @cli_prefix
end

#debugBoolean

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

Returns:

  • (Boolean)


51
52
53
# File 'lib/mini_magick/configuration.rb', line 51

def debug
  @debug
end

#loggerLogger

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.

Returns:

  • (Logger)


59
60
61
# File 'lib/mini_magick/configuration.rb', line 59

def logger
  @logger
end

#processorObject



15
16
17
# File 'lib/mini_magick/configuration.rb', line 15

def processor
  @processor
end

#processor_pathObject



25
26
27
# File 'lib/mini_magick/configuration.rb', line 25

def processor_path
  @processor_path
end

#shell_apiString

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

Returns:

  • (String)


94
95
96
# File 'lib/mini_magick/configuration.rb', line 94

def shell_api
  @shell_api
end

#timeoutInteger

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

Returns:

  • (Integer)


44
45
46
# File 'lib/mini_magick/configuration.rb', line 44

def timeout
  @timeout
end

#validate_on_createBoolean

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`.

Returns:

  • (Boolean)


68
69
70
# File 'lib/mini_magick/configuration.rb', line 68

def validate_on_create
  @validate_on_create
end

#validate_on_writeBoolean

If set to ‘true`, it will `identify` every image that gets written (with 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`.

Returns:

  • (Boolean)


77
78
79
# File 'lib/mini_magick/configuration.rb', line 77

def validate_on_write
  @validate_on_write
end

#whinyBoolean

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

Returns:

  • (Boolean)


85
86
87
# File 'lib/mini_magick/configuration.rb', line 85

def whiny
  @whiny
end

Class Method Details

.extended(base) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/mini_magick/configuration.rb', line 96

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

Instance Method Details

#configure {|self| ... } ⇒ Object

Examples:

MiniMagick.configure do |config|
  config.cli = :graphicsmagick
  config.timeout = 5
end

Yields:

  • (self)


112
113
114
# File 'lib/mini_magick/configuration.rb', line 112

def configure
  yield self
end

#reload_toolsObject

Backwards compatibility



163
164
165
# File 'lib/mini_magick/configuration.rb', line 163

def reload_tools
  warn "MiniMagick.reload_tools is deprecated because it is no longer necessary"
end