mini_magick 3.8.1 → 4.0.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mini_gmagick.rb +2 -1
  3. data/lib/mini_magick/configuration.rb +136 -0
  4. data/lib/mini_magick/image/info.rb +122 -0
  5. data/lib/mini_magick/image.rb +380 -334
  6. data/lib/mini_magick/logger.rb +40 -0
  7. data/lib/mini_magick/shell.rb +48 -0
  8. data/lib/mini_magick/tool/animate.rb +14 -0
  9. data/lib/mini_magick/tool/compare.rb +14 -0
  10. data/lib/mini_magick/tool/composite.rb +14 -0
  11. data/lib/mini_magick/tool/conjure.rb +14 -0
  12. data/lib/mini_magick/tool/convert.rb +14 -0
  13. data/lib/mini_magick/tool/display.rb +14 -0
  14. data/lib/mini_magick/tool/identify.rb +14 -0
  15. data/lib/mini_magick/tool/import.rb +14 -0
  16. data/lib/mini_magick/tool/mogrify.rb +14 -0
  17. data/lib/mini_magick/tool/montage.rb +14 -0
  18. data/lib/mini_magick/tool/stream.rb +14 -0
  19. data/lib/mini_magick/tool.rb +250 -0
  20. data/lib/mini_magick/utilities.rb +23 -50
  21. data/lib/mini_magick/version.rb +5 -5
  22. data/lib/mini_magick.rb +43 -65
  23. data/spec/fixtures/animation.gif +0 -0
  24. data/spec/fixtures/default.jpg +0 -0
  25. data/spec/fixtures/exif.jpg +0 -0
  26. data/spec/fixtures/image.psd +0 -0
  27. data/spec/fixtures/not_an_image.rb +1 -0
  28. data/spec/lib/mini_magick/configuration_spec.rb +66 -0
  29. data/spec/lib/mini_magick/image_spec.rb +367 -406
  30. data/spec/lib/mini_magick/shell_spec.rb +66 -0
  31. data/spec/lib/mini_magick/tool_spec.rb +107 -0
  32. data/spec/lib/mini_magick/utilities_spec.rb +17 -0
  33. data/spec/lib/mini_magick_spec.rb +23 -47
  34. data/spec/spec_helper.rb +17 -25
  35. data/spec/support/helpers.rb +37 -0
  36. metadata +40 -74
  37. data/lib/mini_magick/command_builder.rb +0 -94
  38. data/lib/mini_magick/errors.rb +0 -4
  39. data/spec/files/actually_a_gif.jpg +0 -0
  40. data/spec/files/animation.gif +0 -0
  41. data/spec/files/composited.jpg +0 -0
  42. data/spec/files/erroneous.jpg +0 -0
  43. data/spec/files/layers.psd +0 -0
  44. data/spec/files/leaves (spaced).tiff +0 -0
  45. data/spec/files/not_an_image.php +0 -1
  46. data/spec/files/png.png +0 -0
  47. data/spec/files/simple-minus.gif +0 -0
  48. data/spec/files/simple.gif +0 -0
  49. data/spec/files/trogdor.jpg +0 -0
  50. data/spec/files/trogdor_capitalized.JPG +0 -0
  51. data/spec/lib/mini_magick/command_builder_spec.rb +0 -153
data/lib/mini_magick.rb CHANGED
@@ -1,75 +1,53 @@
1
- require 'mini_magick/command_builder'
2
- require 'mini_magick/errors'
1
+ require 'mini_magick/configuration'
2
+ require 'mini_magick/tool'
3
3
  require 'mini_magick/image'
4
- require 'mini_magick/utilities'
5
4
 
6
5
  module MiniMagick
7
- @validate_on_create = true
8
- @validate_on_write = true
9
6
 
10
- class << self
11
- attr_accessor :processor
12
- attr_accessor :processor_path
13
- attr_accessor :timeout
14
- attr_accessor :debug
15
- attr_accessor :validate_on_create
16
- attr_accessor :validate_on_write
17
-
18
- ##
19
- # Tries to detect the current processor based if any of the processors
20
- # exist. Mogrify have precedence over gm by default.
21
- #
22
- # === Returns
23
- # * [Symbol] The detected procesor
24
- def processor
25
- @processor ||= [:mogrify, :gm].detect do |processor|
26
- MiniMagick::Utilities.which(processor.to_s)
27
- end
28
- end
7
+ extend MiniMagick::Configuration
8
+
9
+ ##
10
+ # You might want to execute only certain blocks of processing with a
11
+ # different CLI, because for example that CLI does that particular thing
12
+ # faster. After the block CLI resets to its previous value.
13
+ #
14
+ # @example
15
+ # MiniMagick.with_cli :graphicsmagick do
16
+ # # operations that are better done with GraphicsMagick
17
+ # end
18
+ def self.with_cli(cli)
19
+ old_cli = self.cli
20
+ self.cli = cli
21
+ yield
22
+ self.cli = old_cli
23
+ end
29
24
 
30
- ##
31
- # Discovers the imagemagick version based on mogrify's output.
32
- #
33
- # === Returns
34
- # * The imagemagick version
35
- def image_magick_version
36
- @@version ||= Gem::Version.create(`mogrify --version`.split(' ')[2].split('-').first)
37
- end
25
+ ##
26
+ # Checks whether the CLI used is ImageMagick.
27
+ #
28
+ # @return [Boolean]
29
+ def self.imagemagick?
30
+ cli == :imagemagick
31
+ end
38
32
 
39
- ##
40
- # The minimum allowed imagemagick version
41
- #
42
- # === Returns
43
- # * The minimum imagemagick version
44
- def minimum_image_magick_version
45
- @@minimum_version ||= Gem::Version.create('6.6.3')
46
- end
33
+ ##
34
+ # Checks whether the CLI used is GraphicsMagick.
35
+ #
36
+ # @return [Boolean]
37
+ def self.graphicsmagick?
38
+ cli == :graphicsmagick
39
+ end
47
40
 
48
- ##
49
- # Checks whether the imagemagick's version is valid
50
- #
51
- # === Returns
52
- # * [Boolean]
53
- def valid_version_installed?
54
- image_magick_version >= minimum_image_magick_version
55
- end
41
+ ##
42
+ # Returns ImageMagick's/GraphicsMagick's version.
43
+ #
44
+ # @return [String]
45
+ def self.cli_version
46
+ output = MiniMagick::Tool::Identify.new(&:version)
47
+ output[/\d+\.\d+\.\d+(-\d+)?/]
48
+ end
56
49
 
57
- ##
58
- # Checks whether the current processory is mogrify.
59
- #
60
- # === Returns
61
- # * [Boolean]
62
- def mogrify?
63
- processor && processor.to_sym == :mogrify
64
- end
50
+ class Error < RuntimeError; end
51
+ class Invalid < StandardError; end
65
52
 
66
- ##
67
- # Checks whether the current processor is graphicsmagick.
68
- #
69
- # === Returns
70
- # * [Boolean]
71
- def gm?
72
- processor && processor.to_sym == :gm
73
- end
74
- end
75
53
  end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ expect(__FILE__).not_to be_an_image
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe MiniMagick::Configuration do
4
+ subject { Object.new.extend(MiniMagick::Configuration) }
5
+
6
+ describe "#configure" do
7
+ it "yields self" do
8
+ expect { |b| subject.configure(&b) }
9
+ .to yield_with_args(subject)
10
+ end
11
+ end
12
+
13
+ describe "#cli" do
14
+ it "can be assigned" do
15
+ subject.cli = :imagemagick
16
+ expect(subject.cli).to eq :imagemagick
17
+ end
18
+
19
+ it "returns :imagemagick if #processor is mogrify" do
20
+ allow(subject).to receive(:processor).and_return("mogrify")
21
+ expect(subject.cli).to eq :imagemagick
22
+ end
23
+
24
+ it "returns :graphicsmagick if #processor is gm" do
25
+ allow(subject).to receive(:processor).and_return("gm")
26
+ expect(subject.cli).to eq :graphicsmagick
27
+ end
28
+
29
+ it "returns nil of #processor is nil" do
30
+ allow(subject).to receive(:processor).and_return(nil)
31
+ expect(subject.cli).to eq nil
32
+ end
33
+ end
34
+
35
+ describe "#cli=" do
36
+ it "raises an error when set to an invalid value" do
37
+ expect { subject.cli = :grapicsmagick }
38
+ .to raise_error(ArgumentError)
39
+ end
40
+ end
41
+
42
+ describe "#processor" do
43
+ it "assigns :mogrify by default" do
44
+ expect(subject.processor).to eq "mogrify"
45
+ end
46
+
47
+ it "assigns :gm if ImageMagick is not available" do
48
+ allow(MiniMagick::Utilities).to receive(:which).with("mogrify").and_return(nil)
49
+ allow(MiniMagick::Utilities).to receive(:which).with("gm").and_return(true)
50
+ expect(subject.processor).to eq "gm"
51
+ end
52
+
53
+ it "returns nil if neither ImageMagick nor GraphicsMagick are available" do
54
+ allow(MiniMagick::Utilities).to receive(:which).with("mogrify").and_return(nil)
55
+ allow(MiniMagick::Utilities).to receive(:which).with("gm").and_return(nil)
56
+ expect(subject.processor).to eq nil
57
+ end
58
+ end
59
+
60
+ describe "#processor=" do
61
+ it "raises an error when set to an invalid value" do
62
+ expect { subject.processor = "mogrfy" }
63
+ .to raise_error(ArgumentError)
64
+ end
65
+ end
66
+ end