Module: MiniMagick::Configuration
- Included in:
- MiniMagick
- Defined in:
- lib/mini_magick/configuration.rb
Constant Summary collapse
- CLI_DETECTION =
{ imagemagick7: "magick", imagemagick: "mogrify", graphicsmagick: "gm", }
Instance Attribute Summary collapse
-
#cli_path ⇒ String
If you set the path of CLI tools, you can get the path of the executables.
-
#cli_prefix ⇒ String+
Adds a prefix to the CLI command.
-
#debug ⇒ Boolean
When get to ‘true`, it outputs each command to STDOUT in their shell version.
-
#logger ⇒ Logger
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.
- #processor_path ⇒ Object
-
#shell_api ⇒ String
Instructs MiniMagick how to execute the shell commands.
-
#timeout ⇒ Integer
If you don’t want commands to take too long, you can set a timeout (in seconds).
-
#validate_on_create ⇒ Boolean
If set to ‘true`, it will `identify` every newly created image, and raise `MiniMagick::Invalid` if the image is not valid.
-
#validate_on_write ⇒ Boolean
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.
-
#whiny ⇒ Boolean
If set to ‘false`, it will not raise errors when ImageMagick returns status code different than 0.
Class Method Summary collapse
Instance Method Summary collapse
-
#cli ⇒ Symbol
Get [ImageMagick](www.imagemagick.org) or [GraphicsMagick](www.graphicsmagick.org).
-
#cli=(value) ⇒ Object
Set whether you want to use [ImageMagick](www.imagemagick.org) or [GraphicsMagick](www.graphicsmagick.org).
- #configure {|self| ... } ⇒ Object
- #processor ⇒ Object
- #processor=(processor) ⇒ Object
-
#reload_tools ⇒ Object
Backwards compatibility.
Instance Attribute Details
#cli_path ⇒ String
If you set the path of CLI tools, you can get the path of the executables.
165 166 167 168 169 170 171 172 173 |
# 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 |
#cli_prefix ⇒ String+
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’]
24 25 26 |
# File 'lib/mini_magick/configuration.rb', line 24 def cli_prefix @cli_prefix end |
#debug ⇒ Boolean
When get to ‘true`, it outputs each command to STDOUT in their shell version.
39 40 41 |
# File 'lib/mini_magick/configuration.rb', line 39 def debug @debug end |
#logger ⇒ Logger
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.
47 48 49 |
# File 'lib/mini_magick/configuration.rb', line 47 def logger @logger end |
#processor_path ⇒ Object
13 14 15 |
# File 'lib/mini_magick/configuration.rb', line 13 def processor_path @processor_path end |
#shell_api ⇒ String
Instructs MiniMagick how to execute the shell commands. Available APIs are “open3” (default) and “posix-spawn” (requires the “posix-spawn” gem).
82 83 84 |
# File 'lib/mini_magick/configuration.rb', line 82 def shell_api @shell_api end |
#timeout ⇒ Integer
If you don’t want commands to take too long, you can set a timeout (in seconds).
32 33 34 |
# File 'lib/mini_magick/configuration.rb', line 32 def timeout @timeout end |
#validate_on_create ⇒ Boolean
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`.
56 57 58 |
# File 'lib/mini_magick/configuration.rb', line 56 def validate_on_create @validate_on_create end |
#validate_on_write ⇒ Boolean
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`.
65 66 67 |
# File 'lib/mini_magick/configuration.rb', line 65 def validate_on_write @validate_on_write end |
#whiny ⇒ Boolean
If set to ‘false`, it will not raise errors when ImageMagick returns status code different than 0. Defaults to `true`.
73 74 75 |
# File 'lib/mini_magick/configuration.rb', line 73 def whiny @whiny end |
Class Method Details
.extended(base) ⇒ Object
84 85 86 87 88 89 90 |
# 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 |
Instance Method Details
#cli ⇒ Symbol
Get [ImageMagick](www.imagemagick.org) or [GraphicsMagick](www.graphicsmagick.org).
134 135 136 137 138 139 140 141 142 143 |
# 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) ⇒ Object
Set whether you want to use [ImageMagick](www.imagemagick.org) or [GraphicsMagick](www.graphicsmagick.org).
149 150 151 152 153 154 155 156 157 |
# 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 |
#configure {|self| ... } ⇒ Object
100 101 102 |
# File 'lib/mini_magick/configuration.rb', line 100 def configure yield self end |
#processor ⇒ Object
111 112 113 114 115 |
# 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) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# 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 ⇒ Object
Backwards compatibility
185 186 187 |
# File 'lib/mini_magick/configuration.rb', line 185 def reload_tools warn "MiniMagick.reload_tools is deprecated because it is no longer necessary" end |