mini_magick 4.13.2 → 5.1.2
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 +4 -4
- data/README.md +96 -112
- data/lib/mini_magick/configuration.rb +20 -133
- data/lib/mini_magick/image/info.rb +7 -60
- data/lib/mini_magick/image.rb +33 -69
- data/lib/mini_magick/shell.rb +18 -45
- data/lib/mini_magick/tool.rb +39 -71
- data/lib/mini_magick/utilities.rb +4 -6
- data/lib/mini_magick/version.rb +2 -2
- data/lib/mini_magick.rb +18 -42
- metadata +31 -33
- data/lib/mini_gmagick.rb +0 -3
- data/lib/mini_magick/tool/animate.rb +0 -14
- data/lib/mini_magick/tool/compare.rb +0 -14
- data/lib/mini_magick/tool/composite.rb +0 -14
- data/lib/mini_magick/tool/conjure.rb +0 -14
- data/lib/mini_magick/tool/convert.rb +0 -14
- data/lib/mini_magick/tool/display.rb +0 -14
- data/lib/mini_magick/tool/identify.rb +0 -14
- data/lib/mini_magick/tool/import.rb +0 -14
- data/lib/mini_magick/tool/magick.rb +0 -14
- data/lib/mini_magick/tool/mogrify.rb +0 -14
- data/lib/mini_magick/tool/mogrify_restricted.rb +0 -15
- data/lib/mini_magick/tool/montage.rb +0 -14
- data/lib/mini_magick/tool/stream.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 573cda9139f6e0b3dea89a7d981006b64b577902cebc65c99b397c298ab069cd
|
4
|
+
data.tar.gz: 6c84cd11d7308fc2555740606cc42caf6be7a404e8b8233443d6591780f38395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '010348f8a6140c1e6df3cf274521cae0935be4d1f262e564456e725d983a7c4962975265ba763c320ccf423841aa323ff78ccd1c045b3553499932f1e1292997'
|
7
|
+
data.tar.gz: 3480cdc918c7ccf0b39c19a520484c89782ee3f6c84aea57eaf69f0efabaae5f92287a087da7f49bf6d1c035e8b2f4d86e380eb1653779c7222cec5133f6a7e4
|
data/README.md
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
[](https://github.com/minimagick/minimagick/actions/workflows/ci.yml)
|
5
5
|
[](https://codeclimate.com/github/minimagick/minimagick)
|
6
6
|
|
7
|
-
A ruby wrapper for [ImageMagick](http://imagemagick.org/)
|
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
|
30
|
-
|
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
|
-
```
|
47
|
-
|
45
|
+
```sh
|
46
|
+
$ bundle add mini_magick
|
48
47
|
```
|
49
48
|
|
50
49
|
## Information
|
51
50
|
|
52
|
-
* [API documentation](
|
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
|
121
|
-
about its interface, see [
|
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 `
|
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,28 @@ 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.
|
242
|
-
config.
|
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
|
243
244
|
end
|
244
245
|
```
|
245
246
|
|
246
|
-
For a
|
247
|
-
[Configuration](
|
247
|
+
For a more information, see
|
248
|
+
[Configuration](https://rubydoc.info/gems/mini_magick/MiniMagick/Configuration) API documentation.
|
248
249
|
|
249
250
|
### Composite
|
250
251
|
|
@@ -277,19 +278,7 @@ end
|
|
277
278
|
|
278
279
|
### Image validation
|
279
280
|
|
280
|
-
|
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:
|
281
|
+
You can test whether an image is valid by running it through `identify`:
|
293
282
|
|
294
283
|
```rb
|
295
284
|
image.valid?
|
@@ -309,67 +298,36 @@ D, [2016-03-19T07:31:36.755338 #87191] DEBUG -- : [0.01s] identify /var/folders/
|
|
309
298
|
|
310
299
|
In Rails you'll probably want to set `MiniMagick.logger = Rails.logger`.
|
311
300
|
|
312
|
-
|
313
|
-
|
314
|
-
Default CLI is ImageMagick, but if you want to use GraphicsMagick, you can
|
315
|
-
specify it in configuration:
|
301
|
+
## Tools
|
316
302
|
|
317
|
-
|
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:
|
303
|
+
If you prefer not to use the `MiniMagick::Image` abstraction, you can use ImageMagick's command-line tools directly:
|
324
304
|
|
325
305
|
```rb
|
326
|
-
MiniMagick.
|
327
|
-
|
328
|
-
|
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"
|
306
|
+
MiniMagick.convert do |convert|
|
307
|
+
convert << "input.jpg"
|
308
|
+
convert.resize("100x100")
|
309
|
+
convert.negate
|
310
|
+
convert << "output.jpg"
|
347
311
|
end #=> `magick input.jpg -resize 100x100 -negate output.jpg`
|
348
312
|
|
349
313
|
# OR
|
350
314
|
|
351
|
-
convert = MiniMagick
|
315
|
+
convert = MiniMagick.convert
|
352
316
|
convert << "input.jpg"
|
353
317
|
convert.resize("100x100")
|
354
318
|
convert.negate
|
355
319
|
convert << "output.jpg"
|
356
|
-
convert.call #=> `
|
320
|
+
convert.call #=> `magick input.jpg -resize 100x100 -negate output.jpg`
|
357
321
|
```
|
358
322
|
|
359
|
-
|
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.
|
323
|
+
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
324
|
|
364
|
-
|
365
|
-
performance of your image processing. We will now show the features available.
|
366
|
-
|
367
|
-
#### Appending
|
325
|
+
### Appending
|
368
326
|
|
369
327
|
The most basic way of building a command is appending strings:
|
370
328
|
|
371
329
|
```rb
|
372
|
-
MiniMagick
|
330
|
+
MiniMagick.convert do |convert|
|
373
331
|
convert << "input.jpg"
|
374
332
|
convert.merge! ["-resize", "500x500", "-negate"]
|
375
333
|
convert << "output.jpg"
|
@@ -396,10 +354,10 @@ convert << "Perspective"
|
|
396
354
|
convert << "0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35"
|
397
355
|
```
|
398
356
|
```
|
399
|
-
|
357
|
+
magick -distort Perspective '0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35'
|
400
358
|
```
|
401
359
|
|
402
|
-
|
360
|
+
### Methods
|
403
361
|
|
404
362
|
Instead of passing in options directly, you can use Ruby methods:
|
405
363
|
|
@@ -409,15 +367,12 @@ convert.rotate(90)
|
|
409
367
|
convert.distort("Perspective", "0,0,0,0 0,45,0,45 69,0,60,10 69,45,60,35")
|
410
368
|
```
|
411
369
|
|
412
|
-
|
413
|
-
`NoMethodError` if you happen to have misspelled an option.
|
414
|
-
|
415
|
-
#### Chaining
|
370
|
+
### Chaining
|
416
371
|
|
417
372
|
Every method call returns `self`, so you can chain them to create logical groups.
|
418
373
|
|
419
374
|
```rb
|
420
|
-
MiniMagick
|
375
|
+
MiniMagick.convert do |convert|
|
421
376
|
convert << "input.jpg"
|
422
377
|
convert.clone(0).background('gray').shadow('80x5+5+5')
|
423
378
|
convert.negate
|
@@ -425,23 +380,23 @@ MiniMagick::Tool::Magick.new do |convert|
|
|
425
380
|
end
|
426
381
|
```
|
427
382
|
|
428
|
-
|
383
|
+
### "Plus" options
|
429
384
|
|
430
385
|
```rb
|
431
|
-
MiniMagick
|
386
|
+
MiniMagick.convert do |convert|
|
432
387
|
convert << "input.jpg"
|
433
388
|
convert.repage.+
|
434
389
|
convert.distort.+("Perspective", "more args")
|
435
390
|
end
|
436
391
|
```
|
437
392
|
```
|
438
|
-
|
393
|
+
magick input.jpg +repage +distort Perspective 'more args'
|
439
394
|
```
|
440
395
|
|
441
|
-
|
396
|
+
### Stacks
|
442
397
|
|
443
398
|
```rb
|
444
|
-
MiniMagick
|
399
|
+
MiniMagick.convert do |convert|
|
445
400
|
convert << "wand.gif"
|
446
401
|
|
447
402
|
convert.stack do |stack|
|
@@ -456,16 +411,16 @@ MiniMagick::Tool::Magick.new do |convert|
|
|
456
411
|
end
|
457
412
|
```
|
458
413
|
```
|
459
|
-
|
414
|
+
magick wand.gif \( wand.gif -rotate 90 -foo bar baz \) images.gif
|
460
415
|
```
|
461
416
|
|
462
|
-
|
417
|
+
### STDIN and STDOUT
|
463
418
|
|
464
419
|
If you want to pass something to standard input, you can pass the `:stdin`
|
465
420
|
option to `#call`:
|
466
421
|
|
467
422
|
```rb
|
468
|
-
identify = MiniMagick
|
423
|
+
identify = MiniMagick.identify
|
469
424
|
identify.stdin # alias for "-"
|
470
425
|
identify.call(stdin: image_content)
|
471
426
|
```
|
@@ -474,14 +429,14 @@ MiniMagick also has `#stdout` alias for "-" for outputting file contents to
|
|
474
429
|
standard output:
|
475
430
|
|
476
431
|
```rb
|
477
|
-
content = MiniMagick
|
432
|
+
content = MiniMagick.convert do |convert|
|
478
433
|
convert << "input.jpg"
|
479
434
|
convert.auto_orient
|
480
435
|
convert.stdout # alias for "-"
|
481
436
|
end
|
482
437
|
```
|
483
438
|
|
484
|
-
|
439
|
+
### Capturing STDERR
|
485
440
|
|
486
441
|
Some MiniMagick tools such as `compare` output the result of the command on
|
487
442
|
standard error, even if the command succeeded. The result of
|
@@ -489,27 +444,57 @@ standard error, even if the command succeeded. The result of
|
|
489
444
|
block, it will yield the stdout, stderr and exit status of the command:
|
490
445
|
|
491
446
|
```rb
|
492
|
-
compare = MiniMagick
|
447
|
+
compare = MiniMagick.compare
|
493
448
|
# build the command
|
494
449
|
compare.call do |stdout, stderr, status|
|
495
450
|
# ...
|
496
451
|
end
|
497
452
|
```
|
498
453
|
|
499
|
-
##
|
454
|
+
## Configuring
|
455
|
+
|
456
|
+
### GraphicsMagick
|
457
|
+
|
458
|
+
As of MiniMagick 5+, [GraphicsMagick](http://www.graphicsmagick.org/) isn't
|
459
|
+
officially supported. This means its installation won't be auto-detected, and no
|
460
|
+
attempts will be made to handle differences in GraphicsMagick API or output.
|
461
|
+
|
462
|
+
However, you can still configure MiniMagick to use it:
|
463
|
+
|
464
|
+
```rb
|
465
|
+
MiniMagick.configure do |config|
|
466
|
+
config.graphicsmagick = true
|
467
|
+
end
|
468
|
+
```
|
469
|
+
|
470
|
+
Some MiniMagick features won't be supported, such as global timeout,
|
471
|
+
`MiniMagick::Image#data` and `MiniMagick::Image#exif`.
|
500
472
|
|
501
|
-
|
473
|
+
### Limiting resources
|
474
|
+
|
475
|
+
ImageMagick supports a number of [environment variables] for controlling its
|
502
476
|
resource limits. For example, you can enforce memory or execution time limits by
|
503
|
-
setting the following
|
477
|
+
setting the following:
|
478
|
+
|
479
|
+
```rb
|
480
|
+
MiniMagick.configure do |config|
|
481
|
+
config.cli_env = {
|
482
|
+
"MAGICK_MEMORY_LIMIT" => "128MiB",
|
483
|
+
"MAGICK_MAP_LIMIT" => "64MiB",
|
484
|
+
"MAGICK_TIME_LIMIT" => "30"
|
485
|
+
}
|
486
|
+
end
|
487
|
+
```
|
504
488
|
|
505
|
-
|
506
|
-
* `MAGICK_MAP_LIMIT=64MiB`
|
507
|
-
* `MAGICK_TIME_LIMIT=30`
|
489
|
+
For time limit you can also use the `timeout` configuration:
|
508
490
|
|
509
|
-
|
510
|
-
|
491
|
+
```rb
|
492
|
+
MiniMagick.configure do |config|
|
493
|
+
config.timeout = 30 # 30 seconds
|
494
|
+
end
|
495
|
+
```
|
511
496
|
|
512
|
-
|
497
|
+
### Changing temporary directory
|
513
498
|
|
514
499
|
ImageMagick allows you to change the temporary directory to process the image file:
|
515
500
|
|
@@ -523,7 +508,7 @@ The example directory `/my/new/tmp_dir` must exist and must be writable.
|
|
523
508
|
|
524
509
|
If not configured, it will default to `Dir.tmpdir`.
|
525
510
|
|
526
|
-
|
511
|
+
### Ignoring STDERR
|
527
512
|
|
528
513
|
If you're receiving warnings from ImageMagick that you don't care about, you
|
529
514
|
can avoid them being forwarded to standard error:
|
@@ -534,9 +519,7 @@ MiniMagick.configure do |config|
|
|
534
519
|
end
|
535
520
|
```
|
536
521
|
|
537
|
-
|
538
|
-
|
539
|
-
### Errors being raised when they shouldn't
|
522
|
+
### Avoiding raising errors
|
540
523
|
|
541
524
|
This gem raises an error when ImageMagick returns a nonzero exit code.
|
542
525
|
Sometimes, however, ImageMagick returns nonzero exit codes when the command
|
@@ -545,15 +528,14 @@ following configuration:
|
|
545
528
|
|
546
529
|
```rb
|
547
530
|
MiniMagick.configure do |config|
|
548
|
-
config.
|
531
|
+
config.errors = false
|
549
532
|
end
|
550
533
|
```
|
551
534
|
|
552
|
-
|
553
|
-
constructor:
|
535
|
+
You can also pass `errors: false` to individual commands:
|
554
536
|
|
555
537
|
```rb
|
556
|
-
MiniMagick
|
538
|
+
MiniMagick.identify(errors: false) do |b|
|
557
539
|
b.help
|
558
540
|
end
|
559
541
|
```
|
@@ -571,3 +553,5 @@ Unlike RMagick, MiniMagick is a much thinner wrapper around ImageMagick.
|
|
571
553
|
* To open files with MiniMagick you use `MiniMagick::Image.open` as you would
|
572
554
|
`Magick::Image.read`. To open a file and directly edit it, use
|
573
555
|
`MiniMagick::Image.new`.
|
556
|
+
|
557
|
+
[environment variables]: https://imagemagick.org/script/resources.php#environment
|
@@ -5,12 +5,11 @@ module MiniMagick
|
|
5
5
|
module Configuration
|
6
6
|
|
7
7
|
##
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# Uses [GraphicsMagick](http://www.graphicsmagick.org/) instead of
|
9
|
+
# ImageMagick, by prefixing commands with `gm` instead of `magick`.
|
10
10
|
#
|
11
|
-
|
12
|
-
|
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.
|
@@ -23,6 +22,16 @@ module MiniMagick
|
|
23
22
|
#
|
24
23
|
attr_accessor :cli_prefix
|
25
24
|
|
25
|
+
##
|
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'}
|
30
|
+
#
|
31
|
+
# @return [Hash]
|
32
|
+
#
|
33
|
+
attr_accessor :cli_env
|
34
|
+
|
26
35
|
##
|
27
36
|
# If you don't want commands to take too long, you can set a timeout (in
|
28
37
|
# seconds).
|
@@ -31,16 +40,8 @@ module MiniMagick
|
|
31
40
|
#
|
32
41
|
attr_accessor :timeout
|
33
42
|
##
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# @return [Boolean]
|
38
|
-
#
|
39
|
-
attr_reader :debug
|
40
|
-
##
|
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.
|
43
|
+
# Logger for commands, default is `Logger.new($stdout)`, but you can
|
44
|
+
# override it, for example if you want the logs to be written to a file.
|
44
45
|
#
|
45
46
|
# @return [Logger]
|
46
47
|
#
|
@@ -53,31 +54,13 @@ module MiniMagick
|
|
53
54
|
#
|
54
55
|
attr_accessor :tmpdir
|
55
56
|
|
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
57
|
##
|
75
58
|
# If set to `false`, it will not raise errors when ImageMagick returns
|
76
59
|
# status code different than 0. Defaults to `true`.
|
77
60
|
#
|
78
61
|
# @return [Boolean]
|
79
62
|
#
|
80
|
-
attr_accessor :
|
63
|
+
attr_accessor :errors
|
81
64
|
|
82
65
|
##
|
83
66
|
# If set to `false`, it will not forward warnings from ImageMagick to
|
@@ -86,118 +69,22 @@ module MiniMagick
|
|
86
69
|
|
87
70
|
def self.extended(base)
|
88
71
|
base.tmpdir = Dir.tmpdir
|
89
|
-
base.
|
90
|
-
base.validate_on_write = true
|
91
|
-
base.whiny = true
|
72
|
+
base.errors = true
|
92
73
|
base.logger = Logger.new($stdout).tap { |l| l.level = Logger::INFO }
|
93
74
|
base.warnings = true
|
75
|
+
base.cli_env = {}.freeze
|
76
|
+
base.graphicsmagick = false
|
94
77
|
end
|
95
78
|
|
96
79
|
##
|
97
80
|
# @yield [self]
|
98
81
|
# @example
|
99
82
|
# MiniMagick.configure do |config|
|
100
|
-
# config.cli = :graphicsmagick
|
101
83
|
# config.timeout = 5
|
102
84
|
# end
|
103
85
|
#
|
104
86
|
def configure
|
105
87
|
yield self
|
106
88
|
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
89
|
end
|
203
90
|
end
|