mini_magick 4.13.2 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44b0562f09fa6d0cc281ad1c4317b8e9915aa60dc6175072dc0cdc872f3d8367
4
- data.tar.gz: 96225cd5bd66e3c0c065cb169057e196becfcdd1e0c883cb7c23f746d76bcda6
3
+ metadata.gz: da1546dc65a1492ca64c0747715e0e6b9b3b641541beac9edd6689a2e9544b8b
4
+ data.tar.gz: b03c897214f43f4d106d90b7fcea2d90ae1b9395afbefcf3810fd2af21fe5095
5
5
  SHA512:
6
- metadata.gz: a39cb409419be063b9cc27fd107a361d94d3f5dbdad719ed1f472efca70650c710160494f22b18f1408df479f29836d29c2bd71262ad1988cdf22caf85a9251a
7
- data.tar.gz: dbb5ba23b0b773a696812ec343f0d267aee1653b0ebfb61ea9560af9c4cac68352b7c936c57233913d8848a1de3c9fe02e31070a94e5f3f0d7f471e444615a55
6
+ metadata.gz: 666e1178b7a89dedcae4de7220c1a41eb812f8a5a1b14143f669a1337deb26271a94ff7cc6698258617b2584dc93129e021b763365039939d83b7b85b47aa8f5
7
+ data.tar.gz: 6db3e4657d4e1db3c368b435ef256ba33becf7b164bea29154faeb209bd168f7c370b2ec915920c2ef1e1f61fde0da43b1753cacc6b829a9365039364b262902
data/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
  [![CI](https://github.com/minimagick/minimagick/actions/workflows/ci.yml/badge.svg)](https://github.com/minimagick/minimagick/actions/workflows/ci.yml)
5
5
  [![Code Climate](https://codeclimate.com/github/minimagick/minimagick/badges/gpa.svg)](https://codeclimate.com/github/minimagick/minimagick)
6
6
 
7
- A ruby wrapper for [ImageMagick](http://imagemagick.org/) or
8
- [GraphicsMagick](http://www.graphicsmagick.org/) command line.
7
+ A ruby wrapper for [ImageMagick](http://imagemagick.org/) command line.
9
8
 
10
9
  ## Why?
11
10
 
@@ -26,8 +25,8 @@ MiniMagick gives you access to all the command line options ImageMagick has
26
25
 
27
26
  ## Requirements
28
27
 
29
- ImageMagick or GraphicsMagick command-line tool has to be installed. You can
30
- check if you have it installed by running
28
+ ImageMagick command-line tool has to be installed. You can check if you have it
29
+ installed by running
31
30
 
32
31
  ```sh
33
32
  $ magick -version
@@ -43,13 +42,13 @@ Compiler: gcc (4.2)
43
42
 
44
43
  Add the gem to your Gemfile:
45
44
 
46
- ```rb
47
- gem "mini_magick"
45
+ ```sh
46
+ $ bundle add mini_magick
48
47
  ```
49
48
 
50
49
  ## Information
51
50
 
52
- * [API documentation](http://rubydoc.info/github/minimagick/minimagick)
51
+ * [API documentation](https://rubydoc.info/gems/mini_magick)
53
52
 
54
53
  ## Usage
55
54
 
@@ -73,7 +72,7 @@ the copy is just temporary, it gets garbage collected when we lose reference
73
72
  to the image.
74
73
 
75
74
  `MiniMagick::Image.open` also accepts URLs, and options passed in will be
76
- forwarded to open-uri.
75
+ forwarded to [open-uri](https://github.com/ruby/open-uri).
77
76
 
78
77
  ```rb
79
78
  image = MiniMagick::Image.open("http://example.com/image.jpg")
@@ -117,8 +116,8 @@ image = MiniMagick::Image.new("input.jpg") do |b|
117
116
  end # the command gets executed
118
117
  ```
119
118
 
120
- The yielded builder is an instance of `MiniMagick::Tool::Mogrify`. To learn more
121
- about its interface, see [Metal](#metal) below.
119
+ The yielded builder is an instance of `MiniMagick::Tool`. To learn more
120
+ about its interface, see [Tools](#tools) below.
122
121
 
123
122
  ### Attributes
124
123
 
@@ -126,7 +125,6 @@ A `MiniMagick::Image` has various handy attributes.
126
125
 
127
126
  ```rb
128
127
  image.type #=> "JPEG"
129
- image.mime_type #=> "image/jpeg"
130
128
  image.width #=> 250
131
129
  image.height #=> 300
132
130
  image.dimensions #=> [250, 300]
@@ -145,7 +143,7 @@ image["%[gamma]"] # "0.9"
145
143
  ```
146
144
 
147
145
  To get the all information about the image, MiniMagick gives you a handy method
148
- which returns the output from `identify -verbose` in hash format:
146
+ which returns the output from `magick input.jpg json:`:
149
147
 
150
148
  ```rb
151
149
  image.data #=>
@@ -193,10 +191,6 @@ image.data #=>
193
191
  # }
194
192
  ```
195
193
 
196
- Note that `MiniMagick::Image#data` is supported only on ImageMagick 6.8.8-3 or
197
- above, for GraphicsMagick or older versions of ImageMagick use
198
- `MiniMagick::Image#details`.
199
-
200
194
  ### Pixels
201
195
 
202
196
  With MiniMagick you can retrieve a matrix of image pixels, where each member of
@@ -221,6 +215,7 @@ pixels = image.get_pixels
221
215
  ### Pixels To Image
222
216
 
223
217
  Sometimes when you have pixels and want to create image from pixels, you can do this to form an image:
218
+
224
219
  ```rb
225
220
  image = MiniMagick::Image.open('/Users/rabin/input.jpg')
226
221
  pixels = image.get_pixels
@@ -229,22 +224,29 @@ dimension = [image.width, image.height]
229
224
  map = 'rgb'
230
225
  image = MiniMagick::Image.get_image_from_pixels(pixels, dimension, map, depth ,'jpg')
231
226
  image.write('/Users/rabin/output.jpg')
232
-
233
227
  ```
234
228
 
235
229
  In this example, the returned pixels should now have equal R, G, and B values.
236
230
 
237
231
  ### Configuration
238
232
 
233
+ Here are the available configuration options with their default values:
234
+
239
235
  ```rb
240
236
  MiniMagick.configure do |config|
241
- config.cli = :graphicsmagick
242
- config.timeout = 5
237
+ config.timeout = nil # number of seconds IM commands may take
238
+ config.errors = true # raise errors non nonzero exit status
239
+ config.warnings = true # forward warnings to standard error
240
+ config.tmdir = Dir.tmpdir # alternative directory for tempfiles
241
+ config.logger = Logger.new($stdout) # where to log IM commands
242
+ config.cli_prefix = nil # add prefix to all IM commands
243
+ config.cli_env = {} # environment variables to set for IM commands
244
+ config.restricted_env = false # when true, block IM commands from accessing system environment variables other than those in cli_env
243
245
  end
244
246
  ```
245
247
 
246
- For a complete list of configuration options, see
247
- [Configuration](http://rubydoc.info/github/minimagick/minimagick/MiniMagick/Configuration).
248
+ For a more information, see
249
+ [Configuration](https://rubydoc.info/gems/mini_magick/MiniMagick/Configuration) API documentation.
248
250
 
249
251
  ### Composite
250
252
 
@@ -277,19 +279,7 @@ end
277
279
 
278
280
  ### Image validation
279
281
 
280
- By default, MiniMagick validates images each time it's opening them. It
281
- validates them by running `identify` on them, and see if ImageMagick finds
282
- them valid. This adds slight overhead to the whole processing. Sometimes it's
283
- safe to assume that all input and output images are valid by default and turn
284
- off validation:
285
-
286
- ```rb
287
- MiniMagick.configure do |config|
288
- config.validate_on_create = false
289
- end
290
- ```
291
-
292
- You can test whether an image is valid:
282
+ You can test whether an image is valid by running it through `identify`:
293
283
 
294
284
  ```rb
295
285
  image.valid?
@@ -309,67 +299,36 @@ D, [2016-03-19T07:31:36.755338 #87191] DEBUG -- : [0.01s] identify /var/folders/
309
299
 
310
300
  In Rails you'll probably want to set `MiniMagick.logger = Rails.logger`.
311
301
 
312
- ### Switching CLIs (ImageMagick \<=\> GraphicsMagick)
313
-
314
- Default CLI is ImageMagick, but if you want to use GraphicsMagick, you can
315
- specify it in configuration:
302
+ ## Tools
316
303
 
317
- ```rb
318
- MiniMagick.configure do |config|
319
- config.cli = :graphicsmagick # or :imagemagick or :imagemagick7
320
- end
321
- ```
322
-
323
- You can also use `.with_cli` to temporary switch the CLI:
304
+ If you prefer not to use the `MiniMagick::Image` abstraction, you can use ImageMagick's command-line tools directly:
324
305
 
325
306
  ```rb
326
- MiniMagick.with_cli(:graphicsmagick) do
327
- # Some processing that GraphicsMagick is better at
328
- end
329
- ```
330
-
331
- **WARNING**: If you're building a multithreaded web application, you should
332
- change the CLI only on application startup. This is because the configuration is
333
- global, so if you change it in a controller action, other threads in the same
334
- process will also have their CLI changed, which could lead to race conditions.
335
-
336
- ### Metal
337
-
338
- If you want to be close to the metal, you can use ImageMagick's command-line
339
- tools directly.
340
-
341
- ```rb
342
- MiniMagick::Tool::Magick.new do |magick|
343
- magick << "input.jpg"
344
- magick.resize("100x100")
345
- magick.negate
346
- magick << "output.jpg"
307
+ MiniMagick.convert do |convert|
308
+ convert << "input.jpg"
309
+ convert.resize("100x100")
310
+ convert.negate
311
+ convert << "output.jpg"
347
312
  end #=> `magick input.jpg -resize 100x100 -negate output.jpg`
348
313
 
349
314
  # OR
350
315
 
351
- convert = MiniMagick::Tool::Convert.new
316
+ convert = MiniMagick.convert
352
317
  convert << "input.jpg"
353
318
  convert.resize("100x100")
354
319
  convert.negate
355
320
  convert << "output.jpg"
356
- convert.call #=> `convert input.jpg -resize 100x100 -negate output.jpg`
321
+ convert.call #=> `magick input.jpg -resize 100x100 -negate output.jpg`
357
322
  ```
358
323
 
359
- If you're on ImageMagick 7, you should probably use `MiniMagick::Tool::Magick`,
360
- though the legacy `MiniMagick::Tool::Convert` and friends will work too. On
361
- ImageMagick 6 `MiniMagick::Tool::Magick` won't be available, so you should
362
- instead use `MiniMagick::Tool::Convert` and friends.
324
+ This way of using MiniMagick is highly recommended if you want to maximize performance of your image processing. There are class methods for each CLI tool: `animate`, `compare`, `composite`, `conjure`, `convert`, `display`, `identify`, `import`, `mogrify` and `stream`. The `MiniMagick.convert` method will use `magick` on ImageMagick 7 and `convert` on ImageMagick 6.
363
325
 
364
- This way of using MiniMagick is highly recommended if you want to maximize
365
- performance of your image processing. We will now show the features available.
366
-
367
- #### Appending
326
+ ### Appending
368
327
 
369
328
  The most basic way of building a command is appending strings:
370
329
 
371
330
  ```rb
372
- MiniMagick::Tool::Magick.new do |convert|
331
+ MiniMagick.convert do |convert|
373
332
  convert << "input.jpg"
374
333
  convert.merge! ["-resize", "500x500", "-negate"]
375
334
  convert << "output.jpg"
@@ -396,10 +355,10 @@ convert << "Perspective"
396
355
  convert << "0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35"
397
356
  ```
398
357
  ```
399
- convert -distort Perspective '0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35'
358
+ magick -distort Perspective '0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35'
400
359
  ```
401
360
 
402
- #### Methods
361
+ ### Methods
403
362
 
404
363
  Instead of passing in options directly, you can use Ruby methods:
405
364
 
@@ -409,15 +368,12 @@ convert.rotate(90)
409
368
  convert.distort("Perspective", "0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35")
410
369
  ```
411
370
 
412
- MiniMagick knows which options each tool has, so you will get an explicit
413
- `NoMethodError` if you happen to have misspelled an option.
414
-
415
- #### Chaining
371
+ ### Chaining
416
372
 
417
373
  Every method call returns `self`, so you can chain them to create logical groups.
418
374
 
419
375
  ```rb
420
- MiniMagick::Tool::Magick.new do |convert|
376
+ MiniMagick.convert do |convert|
421
377
  convert << "input.jpg"
422
378
  convert.clone(0).background('gray').shadow('80x5+5+5')
423
379
  convert.negate
@@ -425,23 +381,23 @@ MiniMagick::Tool::Magick.new do |convert|
425
381
  end
426
382
  ```
427
383
 
428
- #### "Plus" options
384
+ ### "Plus" options
429
385
 
430
386
  ```rb
431
- MiniMagick::Tool::Magick.new do |convert|
387
+ MiniMagick.convert do |convert|
432
388
  convert << "input.jpg"
433
389
  convert.repage.+
434
390
  convert.distort.+("Perspective", "more args")
435
391
  end
436
392
  ```
437
393
  ```
438
- convert input.jpg +repage +distort Perspective 'more args'
394
+ magick input.jpg +repage +distort Perspective 'more args'
439
395
  ```
440
396
 
441
- #### Stacks
397
+ ### Stacks
442
398
 
443
399
  ```rb
444
- MiniMagick::Tool::Magick.new do |convert|
400
+ MiniMagick.convert do |convert|
445
401
  convert << "wand.gif"
446
402
 
447
403
  convert.stack do |stack|
@@ -456,16 +412,16 @@ MiniMagick::Tool::Magick.new do |convert|
456
412
  end
457
413
  ```
458
414
  ```
459
- convert wand.gif \( wand.gif -rotate 90 -foo bar baz \) images.gif
415
+ magick wand.gif \( wand.gif -rotate 90 -foo bar baz \) images.gif
460
416
  ```
461
417
 
462
- #### STDIN and STDOUT
418
+ ### STDIN and STDOUT
463
419
 
464
420
  If you want to pass something to standard input, you can pass the `:stdin`
465
421
  option to `#call`:
466
422
 
467
423
  ```rb
468
- identify = MiniMagick::Tool::Identify.new
424
+ identify = MiniMagick.identify
469
425
  identify.stdin # alias for "-"
470
426
  identify.call(stdin: image_content)
471
427
  ```
@@ -474,14 +430,14 @@ MiniMagick also has `#stdout` alias for "-" for outputting file contents to
474
430
  standard output:
475
431
 
476
432
  ```rb
477
- content = MiniMagick::Tool::Magick.new do |convert|
433
+ content = MiniMagick.convert do |convert|
478
434
  convert << "input.jpg"
479
435
  convert.auto_orient
480
436
  convert.stdout # alias for "-"
481
437
  end
482
438
  ```
483
439
 
484
- #### Capturing STDERR
440
+ ### Capturing STDERR
485
441
 
486
442
  Some MiniMagick tools such as `compare` output the result of the command on
487
443
  standard error, even if the command succeeded. The result of
@@ -489,27 +445,57 @@ standard error, even if the command succeeded. The result of
489
445
  block, it will yield the stdout, stderr and exit status of the command:
490
446
 
491
447
  ```rb
492
- compare = MiniMagick::Tool::Compare.new
448
+ compare = MiniMagick.compare
493
449
  # build the command
494
450
  compare.call do |stdout, stderr, status|
495
451
  # ...
496
452
  end
497
453
  ```
498
454
 
499
- ## Limiting resources
455
+ ## Configuring
456
+
457
+ ### GraphicsMagick
458
+
459
+ As of MiniMagick 5+, [GraphicsMagick](http://www.graphicsmagick.org/) isn't
460
+ officially supported. This means its installation won't be auto-detected, and no
461
+ attempts will be made to handle differences in GraphicsMagick API or output.
462
+
463
+ However, you can still configure MiniMagick to use it:
464
+
465
+ ```rb
466
+ MiniMagick.configure do |config|
467
+ config.graphicsmagick = true
468
+ end
469
+ ```
470
+
471
+ Some MiniMagick features won't be supported, such as global timeout,
472
+ `MiniMagick::Image#data` and `MiniMagick::Image#exif`.
500
473
 
501
- ImageMagick supports a number of environment variables for controlling its
474
+ ### Limiting resources
475
+
476
+ ImageMagick supports a number of [environment variables] for controlling its
502
477
  resource limits. For example, you can enforce memory or execution time limits by
503
- setting the following variables in your application's process environment:
478
+ setting the following:
479
+
480
+ ```rb
481
+ MiniMagick.configure do |config|
482
+ config.cli_env = {
483
+ "MAGICK_MEMORY_LIMIT" => "128MiB",
484
+ "MAGICK_MAP_LIMIT" => "64MiB",
485
+ "MAGICK_TIME_LIMIT" => "30"
486
+ }
487
+ end
488
+ ```
504
489
 
505
- * `MAGICK_MEMORY_LIMIT=128MiB`
506
- * `MAGICK_MAP_LIMIT=64MiB`
507
- * `MAGICK_TIME_LIMIT=30`
490
+ For time limit you can also use the `timeout` configuration:
508
491
 
509
- For a full list of variables and description, see [ImageMagick's resources
510
- documentation](http://www.imagemagick.org/script/resources.php#environment).
492
+ ```rb
493
+ MiniMagick.configure do |config|
494
+ config.timeout = 30 # 30 seconds
495
+ end
496
+ ```
511
497
 
512
- ## Changing temporary directory
498
+ ### Changing temporary directory
513
499
 
514
500
  ImageMagick allows you to change the temporary directory to process the image file:
515
501
 
@@ -523,7 +509,7 @@ The example directory `/my/new/tmp_dir` must exist and must be writable.
523
509
 
524
510
  If not configured, it will default to `Dir.tmpdir`.
525
511
 
526
- ## Ignoring STDERR
512
+ ### Ignoring STDERR
527
513
 
528
514
  If you're receiving warnings from ImageMagick that you don't care about, you
529
515
  can avoid them being forwarded to standard error:
@@ -534,9 +520,7 @@ MiniMagick.configure do |config|
534
520
  end
535
521
  ```
536
522
 
537
- ## Troubleshooting
538
-
539
- ### Errors being raised when they shouldn't
523
+ ### Avoiding raising errors
540
524
 
541
525
  This gem raises an error when ImageMagick returns a nonzero exit code.
542
526
  Sometimes, however, ImageMagick returns nonzero exit codes when the command
@@ -545,15 +529,14 @@ following configuration:
545
529
 
546
530
  ```rb
547
531
  MiniMagick.configure do |config|
548
- config.whiny = false
532
+ config.errors = false
549
533
  end
550
534
  ```
551
535
 
552
- If you're using the tool directly, you can pass `whiny: false` value to the
553
- constructor:
536
+ You can also pass `errors: false` to individual commands:
554
537
 
555
538
  ```rb
556
- MiniMagick::Tool::Identify.new(whiny: false) do |b|
539
+ MiniMagick.identify(errors: false) do |b|
557
540
  b.help
558
541
  end
559
542
  ```
@@ -571,3 +554,5 @@ Unlike RMagick, MiniMagick is a much thinner wrapper around ImageMagick.
571
554
  * To open files with MiniMagick you use `MiniMagick::Image.open` as you would
572
555
  `Magick::Image.read`. To open a file and directly edit it, use
573
556
  `MiniMagick::Image.new`.
557
+
558
+ [environment variables]: https://imagemagick.org/script/resources.php#environment
@@ -5,12 +5,11 @@ module MiniMagick
5
5
  module Configuration
6
6
 
7
7
  ##
8
- # If you don't have the CLI tools in your PATH, you can set the path to the
9
- # executables.
8
+ # Uses [GraphicsMagick](http://www.graphicsmagick.org/) instead of
9
+ # ImageMagick, by prefixing commands with `gm` instead of `magick`.
10
10
  #
11
- attr_writer :cli_path
12
- # @private (for backwards compatibility)
13
- attr_accessor :processor_path
11
+ # @return [Boolean]
12
+ attr_accessor :graphicsmagick
14
13
 
15
14
  ##
16
15
  # Adds a prefix to the CLI command.
@@ -24,23 +23,35 @@ module MiniMagick
24
23
  attr_accessor :cli_prefix
25
24
 
26
25
  ##
27
- # If you don't want commands to take too long, you can set a timeout (in
28
- # seconds).
26
+ # Adds environment variables to every CLI command call.
27
+ # For example, you could use it to set `LD_PRELOAD="/path/to/libsomething.so"`.
28
+ # Must be a hash of strings keyed to valid environment variable name strings.
29
+ # e.g. {'MY_ENV' => 'my value'}
29
30
  #
30
- # @return [Integer]
31
+ # @return [Hash]
31
32
  #
32
- attr_accessor :timeout
33
+ attr_accessor :cli_env
34
+
33
35
  ##
34
- # When get to `true`, it outputs each command to STDOUT in their shell
35
- # version.
36
+ # If set to true, Open3 will restrict system calls to access only
37
+ # environment variables defined in :cli_env, plus HOME, PATH, and LANG
38
+ # since those are required for such system calls. It will not pass on any
39
+ # other environment variables from the system.
36
40
  #
37
41
  # @return [Boolean]
38
42
  #
39
- attr_reader :debug
43
+ attr_accessor :restricted_env
44
+
40
45
  ##
41
- # Logger for {#debug}, default is `MiniMagick::Logger.new(STDOUT)`, but
42
- # you can override it, for example if you want the logs to be written to
43
- # a file.
46
+ # If you don't want commands to take too long, you can set a timeout (in
47
+ # seconds).
48
+ #
49
+ # @return [Integer]
50
+ #
51
+ attr_accessor :timeout
52
+ ##
53
+ # Logger for commands, default is `Logger.new($stdout)`, but you can
54
+ # override it, for example if you want the logs to be written to a file.
44
55
  #
45
56
  # @return [Logger]
46
57
  #
@@ -53,31 +64,13 @@ module MiniMagick
53
64
  #
54
65
  attr_accessor :tmpdir
55
66
 
56
- ##
57
- # If set to `true`, it will `identify` every newly created image, and raise
58
- # `MiniMagick::Invalid` if the image is not valid. Useful for validating
59
- # user input, although it adds a bit of overhead. Defaults to `true`.
60
- #
61
- # @return [Boolean]
62
- #
63
- attr_accessor :validate_on_create
64
- ##
65
- # If set to `true`, it will `identify` every image that gets written (with
66
- # {MiniMagick::Image#write}), and raise `MiniMagick::Invalid` if the image
67
- # is not valid. Useful for validating that processing was successful,
68
- # although it adds a bit of overhead. Defaults to `true`.
69
- #
70
- # @return [Boolean]
71
- #
72
- attr_accessor :validate_on_write
73
-
74
67
  ##
75
68
  # If set to `false`, it will not raise errors when ImageMagick returns
76
69
  # status code different than 0. Defaults to `true`.
77
70
  #
78
71
  # @return [Boolean]
79
72
  #
80
- attr_accessor :whiny
73
+ attr_accessor :errors
81
74
 
82
75
  ##
83
76
  # If set to `false`, it will not forward warnings from ImageMagick to
@@ -86,118 +79,23 @@ module MiniMagick
86
79
 
87
80
  def self.extended(base)
88
81
  base.tmpdir = Dir.tmpdir
89
- base.validate_on_create = true
90
- base.validate_on_write = true
91
- base.whiny = true
82
+ base.errors = true
92
83
  base.logger = Logger.new($stdout).tap { |l| l.level = Logger::INFO }
93
84
  base.warnings = true
85
+ base.cli_env = {}.freeze
86
+ base.restricted_env = false
87
+ base.graphicsmagick = false
94
88
  end
95
89
 
96
90
  ##
97
91
  # @yield [self]
98
92
  # @example
99
93
  # MiniMagick.configure do |config|
100
- # config.cli = :graphicsmagick
101
94
  # config.timeout = 5
102
95
  # end
103
96
  #
104
97
  def configure
105
98
  yield self
106
99
  end
107
-
108
- CLI_DETECTION = {
109
- imagemagick7: "magick",
110
- imagemagick: "mogrify",
111
- graphicsmagick: "gm",
112
- }
113
-
114
- # @private (for backwards compatibility)
115
- def processor
116
- @processor ||= CLI_DETECTION.values.detect do |processor|
117
- MiniMagick::Utilities.which(processor)
118
- end
119
- end
120
-
121
- # @private (for backwards compatibility)
122
- def processor=(processor)
123
- @processor = processor.to_s
124
-
125
- unless CLI_DETECTION.value?(@processor)
126
- raise ArgumentError,
127
- "processor has to be set to either \"magick\", \"mogrify\" or \"gm\"" \
128
- ", was set to #{@processor.inspect}"
129
- end
130
- end
131
-
132
- ##
133
- # Get [ImageMagick](http://www.imagemagick.org) or
134
- # [GraphicsMagick](http://www.graphicsmagick.org).
135
- #
136
- # @return [Symbol] `:imagemagick` or `:graphicsmagick`
137
- #
138
- def cli
139
- if instance_variable_defined?("@cli")
140
- instance_variable_get("@cli")
141
- else
142
- cli = CLI_DETECTION.key(processor) or
143
- fail MiniMagick::Error, "You must have ImageMagick or GraphicsMagick installed"
144
-
145
- instance_variable_set("@cli", cli)
146
- end
147
- end
148
-
149
- ##
150
- # Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
151
- # [GraphicsMagick](http://www.graphicsmagick.org).
152
- #
153
- def cli=(value)
154
- @cli = value
155
-
156
- if not CLI_DETECTION.key?(@cli)
157
- raise ArgumentError,
158
- "CLI has to be set to either :imagemagick, :imagemagick7 or :graphicsmagick" \
159
- ", was set to #{@cli.inspect}"
160
- end
161
- end
162
-
163
- ##
164
- # If you set the path of CLI tools, you can get the path of the
165
- # executables.
166
- #
167
- # @return [String]
168
- #
169
- def cli_path
170
- if instance_variable_defined?("@cli_path")
171
- instance_variable_get("@cli_path")
172
- else
173
- processor_path = instance_variable_get("@processor_path") if instance_variable_defined?("@processor_path")
174
-
175
- instance_variable_set("@cli_path", processor_path)
176
- end
177
- end
178
-
179
- ##
180
- # When set to `true`, it outputs each command to STDOUT in their shell
181
- # version.
182
- #
183
- def debug=(value)
184
- warn "MiniMagick.debug is deprecated and will be removed in MiniMagick 5. Use `MiniMagick.logger.level = Logger::DEBUG` instead."
185
- logger.level = value ? Logger::DEBUG : Logger::INFO
186
- end
187
-
188
- def shell_api=(value)
189
- warn "MiniMagick.shell_api is deprecated and will be removed in MiniMagick 5. The posix-spawn gem doesn't improve performance recent Ruby versions anymore, so support for it will be removed."
190
- @shell_api = value
191
- end
192
-
193
- def shell_api
194
- @shell_api || "open3"
195
- end
196
-
197
- # Backwards compatibility
198
- def reload_tools
199
- warn "MiniMagick.reload_tools is deprecated because it is no longer necessary"
200
- end
201
-
202
100
  end
203
101
  end