mini_magick 3.8.1 → 4.0.0.rc

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.

Potentially problematic release.


This version of mini_magick might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mini_gmagick.rb +2 -1
  3. data/lib/mini_magick.rb +43 -65
  4. data/lib/mini_magick/configuration.rb +136 -0
  5. data/lib/mini_magick/image.rb +356 -336
  6. data/lib/mini_magick/image/info.rb +104 -0
  7. data/lib/mini_magick/logger.rb +40 -0
  8. data/lib/mini_magick/shell.rb +46 -0
  9. data/lib/mini_magick/tool.rb +233 -0
  10. data/lib/mini_magick/tool/animate.rb +14 -0
  11. data/lib/mini_magick/tool/compare.rb +14 -0
  12. data/lib/mini_magick/tool/composite.rb +14 -0
  13. data/lib/mini_magick/tool/conjure.rb +14 -0
  14. data/lib/mini_magick/tool/convert.rb +14 -0
  15. data/lib/mini_magick/tool/display.rb +14 -0
  16. data/lib/mini_magick/tool/identify.rb +14 -0
  17. data/lib/mini_magick/tool/import.rb +14 -0
  18. data/lib/mini_magick/tool/mogrify.rb +14 -0
  19. data/lib/mini_magick/tool/montage.rb +14 -0
  20. data/lib/mini_magick/tool/stream.rb +14 -0
  21. data/lib/mini_magick/utilities.rb +23 -50
  22. data/lib/mini_magick/version.rb +6 -6
  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 +318 -410
  30. data/spec/lib/mini_magick/shell_spec.rb +66 -0
  31. data/spec/lib/mini_magick/tool_spec.rb +90 -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 +42 -76
  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
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe MiniMagick::Shell do
4
+ subject { described_class.new }
5
+
6
+ describe "#run" do
7
+ it "calls #execute with the command" do
8
+ expect(subject).to receive(:execute).and_call_original
9
+ subject.run(%W[identify #{image_path}])
10
+ end
11
+
12
+ it "returns stdout" do
13
+ allow(subject).to receive(:execute).and_return(["stdout", "stderr", 0])
14
+ output = subject.run(%W[foo])
15
+ expect(output).to eq "stdout"
16
+ end
17
+
18
+ it "uses stderr for error messages" do
19
+ allow(subject).to receive(:execute).and_return(["", "stderr", 1])
20
+ expect { subject.run(%W[foo]) }
21
+ .to raise_error(MiniMagick::Error, /`foo`.*stderr/m)
22
+ end
23
+
24
+ it "raises an error when executable wasn't found" do
25
+ allow(subject).to receive(:execute).and_return(["", "not found", 127])
26
+ expect { subject.run(%W[foo]) }
27
+ .to raise_error(MiniMagick::Error, /not found/)
28
+ end
29
+
30
+ it "raises errors only in whiny mode" do
31
+ subject = described_class.new(false)
32
+ allow(subject).to receive(:execute).and_return(["stdout", "", 127])
33
+ expect(subject.run(%W[foo])).to eq "stdout"
34
+ end
35
+ end
36
+
37
+ describe "#execute" do
38
+ it "executes the command in the shell" do
39
+ stdout, * = subject.execute(%W[identify #{image_path(:gif)}])
40
+ expect(stdout).to match("GIF")
41
+ end
42
+
43
+ it "timeouts afer a period of time" do
44
+ allow(MiniMagick).to receive(:timeout).and_return(0.001)
45
+ expect { subject.execute(%W[identify -format %[EXIF:*] #{image_path(:exif)}]) }
46
+ .to raise_error(Timeout::Error)
47
+ end
48
+
49
+ it "logs the command and execution time in debug mode" do
50
+ allow(MiniMagick).to receive(:debug).and_return(true)
51
+ expect { subject.execute(%W[identify #{image_path(:gif)}]) }.
52
+ to output(/\[\d+.\d+s\] identify #{image_path(:gif)}/).to_stdout
53
+ end
54
+
55
+ it "returns an appropriate response when command wasn't found" do
56
+ stdout, stderr, code = subject.execute(%W[unexisting command])
57
+ expect(code).to eq 127
58
+ expect(stderr).to match(/not found/)
59
+ end
60
+
61
+ it "doesn't break on spaces" do
62
+ stdout, * = subject.execute(["identify", "-format", "%w %h", image_path])
63
+ expect(stdout).to match(/\d+ \d+/)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe MiniMagick::Tool do
4
+ subject { MiniMagick::Tool::Identify.new }
5
+
6
+ describe "#call" do
7
+ it "calls the shell to run the command" do
8
+ subject << image_path(:gif)
9
+ output = subject.call
10
+ expect(output).to match("GIF")
11
+ end
12
+
13
+ it "strips the output" do
14
+ subject << image_path
15
+ output = subject.call
16
+ expect(output).not_to end_with("\n")
17
+ end
18
+ end
19
+
20
+ describe ".new" do
21
+ it "accepts a block, and immediately executes the command" do
22
+ output = described_class.new("identify") do |builder|
23
+ builder << image_path(:gif)
24
+ end
25
+ expect(output).to match("GIF")
26
+ end
27
+ end
28
+
29
+ describe "#command" do
30
+ it "includes the executable and the arguments" do
31
+ allow(subject).to receive(:args).and_return(%W[-list Command])
32
+ expect(subject.command).to include(*%W[identify -list Command])
33
+ end
34
+ end
35
+
36
+ describe "#executable" do
37
+ it "prepends 'gm' to the command list when using GraphicsMagick" do
38
+ allow(MiniMagick).to receive(:cli).and_return(:graphicsmagick)
39
+ expect(subject.executable).to eq %W[gm identify]
40
+ end
41
+
42
+ it "respects #cli_path" do
43
+ allow(MiniMagick).to receive(:cli).and_return(:imagemagick)
44
+ allow(MiniMagick).to receive(:cli_path).and_return("path/to/cli")
45
+ expect(subject.executable).to eq %W[path/to/cli/identify]
46
+ end
47
+ end
48
+
49
+ describe "#<<" do
50
+ it "adds argument to the args list" do
51
+ subject << "foo" << "bar"
52
+ expect(subject.args).to eq %W[foo bar]
53
+ end
54
+ end
55
+
56
+ describe "#+" do
57
+ it "switches the last option to + form" do
58
+ subject.help.+
59
+ subject.debug.+ 8
60
+ expect(subject.args).to eq %W[+help +debug 8]
61
+ end
62
+ end
63
+
64
+ ["ImageMagick", "GraphicsMagick"].each do |cli|
65
+ context "with #{cli}", cli: cli.downcase.to_sym do
66
+ it "adds dynamically generated operator methods" do
67
+ subject.help.depth(8)
68
+ expect(subject.args).to eq %W[-help -depth 8]
69
+ end
70
+
71
+ it "doesn't just delegate to #method_missing" do
72
+ expect(subject.class.instance_methods).to include(:help)
73
+ end
74
+
75
+ it "adds dynamically generated creation operator methods" do
76
+ subject.radial_gradient.canvas "khaki"
77
+ expect(subject.args).to eq %W[radial-gradient: canvas:khaki]
78
+ end
79
+ end
80
+ end
81
+
82
+ it "resets the dynamically generated operator methods on CLI change" do
83
+ MiniMagick.cli = :imagemagick
84
+ expect(subject).to respond_to(:quiet)
85
+
86
+ MiniMagick.cli = :graphicsmagick
87
+ expect(subject).not_to respond_to(:quiet)
88
+ expect(subject).to respond_to(:ping)
89
+ end
90
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe MiniMagick::Utilities do
4
+ describe ".which" do
5
+ it "identifies when mogrify exists" do
6
+ expect(MiniMagick::Utilities.which('mogrify')).not_to be_nil
7
+ end
8
+
9
+ it "identifies when gm exists" do
10
+ expect(MiniMagick::Utilities.which('gm')).not_to be_nil
11
+ end
12
+
13
+ it "returns nil on nonexistent executables" do
14
+ expect(MiniMagick::Utilities.which('yogrify')).to be_nil
15
+ end
16
+ end
17
+ end
@@ -1,63 +1,39 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe MiniMagick do
4
- context 'which util' do
5
- it 'identifies when mogrify exists' do
6
- expect(MiniMagick::Utilities.which('mogrify')).not_to be_nil
3
+ RSpec.describe MiniMagick do
4
+ describe ".imagemagick?" do
5
+ it "returns true if CLI is minimagick" do
6
+ allow(described_class).to receive(:cli).and_return(:imagemagick)
7
+ expect(described_class.imagemagick?).to eq true
7
8
  end
8
9
 
9
- it 'identifies when gm exists' do
10
- expect(MiniMagick::Utilities.which('gm')).not_to be_nil
11
- end
12
-
13
- it 'returns nil on nonexistent executables' do
14
- expect(MiniMagick::Utilities.which('yogrify')).to be_nil
10
+ it "returns false if CLI isn't minimagick" do
11
+ allow(described_class).to receive(:cli).and_return(:graphicsmagick)
12
+ expect(described_class.imagemagick?).to eq false
15
13
  end
16
14
  end
17
15
 
18
- context '.mogrify?' do
19
- it 'returns true if minimagick is using mogrify' do
20
- described_class.processor = :mogrify
21
- expect(described_class.mogrify?).to eq true
22
- end
23
-
24
- it 'returns false if minimagick is not using mogrify' do
25
- described_class.processor = :gm
26
- expect(described_class.mogrify?).to eq false
27
- end
28
-
29
- it 'sets the processor if not set' do
30
- described_class.processor = nil
31
- described_class.mogrify?
32
- expect(described_class.processor).to eq :mogrify
33
- end
34
- end
35
-
36
- context '.gm?' do
37
- it 'returns true if minimagick is using gm' do
38
- described_class.processor = :gm
39
- expect(described_class).to be_gm
40
- end
41
-
42
- it 'returns false if minimagick is not using gm' do
43
- described_class.processor = :mogrify
44
- expect(described_class).not_to be_gm
16
+ describe ".graphicsmagick?" do
17
+ it "returns true if CLI is graphicsmagick" do
18
+ allow(described_class).to receive(:cli).and_return(:graphicsmagick)
19
+ expect(described_class.graphicsmagick?).to eq true
45
20
  end
46
21
 
47
- it 'sets the processor if not set' do
48
- described_class.processor = nil
49
- described_class.gm?
50
- expect(described_class.processor).to eq :mogrify
22
+ it "returns false if CLI isn't graphicsmagick" do
23
+ allow(described_class).to receive(:cli).and_return(:imagemagick)
24
+ expect(described_class.graphicsmagick?).to eq false
51
25
  end
52
26
  end
53
27
 
54
- context 'validation' do
55
- it 'validates on create' do
56
- expect(MiniMagick.validate_on_create).to eq(true)
28
+ describe ".cli_version" do
29
+ it "returns ImageMagick's version" do
30
+ allow(described_class).to receive(:cli).and_return(:imagemagick)
31
+ expect(described_class.cli_version).to match(/^\d+\.\d+\.\d+-\d+$/)
57
32
  end
58
33
 
59
- it 'validates on write' do
60
- expect(MiniMagick.validate_on_write).to eq(true)
34
+ it "returns GraphicsMagick's version" do
35
+ allow(described_class).to receive(:cli).and_return(:graphicsmagick)
36
+ expect(described_class.cli_version).to match(/^\d+\.\d+\.\d+$/)
61
37
  end
62
38
  end
63
39
  end
@@ -1,29 +1,21 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'rspec'
4
- require 'mocha/api'
1
+ require "bundler/setup"
2
+ require "mini_magick"
3
+ require "pry"
5
4
 
6
- require 'mini_magick'
5
+ require_relative "support/helpers"
7
6
 
8
7
  RSpec.configure do |config|
9
- config.mock_framework = :mocha
10
- config.color = true
11
- config.formatter = 'documentation'
12
- config.raise_errors_for_deprecations!
13
- end
8
+ config.disable_monkey_patching!
9
+ config.formatter = "documentation"
10
+ config.color = true
11
+ config.fail_fast = true unless ENV["CI"]
14
12
 
15
- # Image files from testunit port to RSpec
16
- test_files = File.expand_path(File.dirname(__FILE__) + '/files')
17
- TEST_FILES_PATH = test_files
18
- SIMPLE_IMAGE_PATH = test_files + '/simple.gif'
19
- MINUS_IMAGE_PATH = test_files + '/simple-minus.gif'
20
- TIFF_IMAGE_PATH = test_files + '/leaves (spaced).tiff'
21
- NOT_AN_IMAGE_PATH = test_files + '/not_an_image.php'
22
- GIF_WITH_JPG_EXT = test_files + '/actually_a_gif.jpg'
23
- EXIF_IMAGE_PATH = test_files + '/trogdor.jpg'
24
- CAP_EXT_PATH = test_files + '/trogdor_capitalized.JPG'
25
- ANIMATION_PATH = test_files + '/animation.gif'
26
- PNG_PATH = test_files + '/png.png'
27
- COMP_IMAGE_PATH = test_files + '/composited.jpg'
28
- ERRONEOUS_IMAGE_PATH = test_files + '/erroneous.jpg'
29
- PSD_IMAGE_PATH = test_files + '/layers.psd'
13
+ [:imagemagick, :graphicsmagick].each do |cli|
14
+ config.around(cli: cli) do |example|
15
+ MiniMagick.with_cli(cli) { example.run }
16
+ end
17
+ config.around(skip_cli: cli) do |example|
18
+ example.run unless example.metadata[:cli] == cli
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ require "tempfile"
2
+
3
+ module Helpers
4
+ def image_path(type = :default)
5
+ if type != :without_extension
6
+ File.join("spec/fixtures",
7
+ case type
8
+ when :default, :jpg then "default.jpg"
9
+ when :animation, :gif then "animation.gif"
10
+ when :pdf then "document.pdf"
11
+ when :psd then "image.psd"
12
+ when :exif then "exif.jpg"
13
+ when :not then "not_an_image.rb"
14
+ else
15
+ fail "image #{type.inspect} doesn't exist"
16
+ end
17
+ )
18
+ else
19
+ path = random_path
20
+ FileUtils.cp image_path, path
21
+ path
22
+ end
23
+ end
24
+
25
+ def image_url
26
+ "https://avatars2.githubusercontent.com/u/795488?v=2&s=40"
27
+ end
28
+
29
+ def random_path(basename = "")
30
+ @tempfile = Tempfile.open(basename)
31
+ @tempfile.path
32
+ end
33
+ end
34
+
35
+ RSpec.configure do |config|
36
+ config.include Helpers
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1
4
+ version: 4.0.0.rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -12,22 +12,8 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-09-11 00:00:00.000000000 Z
15
+ date: 2014-10-05 00:00:00.000000000 Z
16
16
  dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: subexec
19
- requirement: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - "~>"
22
- - !ruby/object:Gem::Version
23
- version: 0.2.1
24
- type: :runtime
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: 0.2.1
31
17
  - !ruby/object:Gem::Dependency
32
18
  name: rake
33
19
  requirement: !ruby/object:Gem::Requirement
@@ -42,48 +28,20 @@ dependencies:
42
28
  - - ">="
43
29
  - !ruby/object:Gem::Version
44
30
  version: '0'
45
- - !ruby/object:Gem::Dependency
46
- name: test-unit
47
- requirement: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- type: :development
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
31
  - !ruby/object:Gem::Dependency
60
32
  name: rspec
61
33
  requirement: !ruby/object:Gem::Requirement
62
34
  requirements:
63
35
  - - "~>"
64
36
  - !ruby/object:Gem::Version
65
- version: 3.0.0
37
+ version: 3.1.0
66
38
  type: :development
67
39
  prerelease: false
68
40
  version_requirements: !ruby/object:Gem::Requirement
69
41
  requirements:
70
42
  - - "~>"
71
43
  - !ruby/object:Gem::Version
72
- version: 3.0.0
73
- - !ruby/object:Gem::Dependency
74
- name: mocha
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '0'
80
- type: :development
81
- prerelease: false
82
- version_requirements: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: '0'
44
+ version: 3.1.0
87
45
  description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
88
46
  email:
89
47
  - probablycorey@gmail.com
@@ -99,27 +57,38 @@ files:
99
57
  - Rakefile
100
58
  - lib/mini_gmagick.rb
101
59
  - lib/mini_magick.rb
102
- - lib/mini_magick/command_builder.rb
103
- - lib/mini_magick/errors.rb
60
+ - lib/mini_magick/configuration.rb
104
61
  - lib/mini_magick/image.rb
62
+ - lib/mini_magick/image/info.rb
63
+ - lib/mini_magick/logger.rb
64
+ - lib/mini_magick/shell.rb
65
+ - lib/mini_magick/tool.rb
66
+ - lib/mini_magick/tool/animate.rb
67
+ - lib/mini_magick/tool/compare.rb
68
+ - lib/mini_magick/tool/composite.rb
69
+ - lib/mini_magick/tool/conjure.rb
70
+ - lib/mini_magick/tool/convert.rb
71
+ - lib/mini_magick/tool/display.rb
72
+ - lib/mini_magick/tool/identify.rb
73
+ - lib/mini_magick/tool/import.rb
74
+ - lib/mini_magick/tool/mogrify.rb
75
+ - lib/mini_magick/tool/montage.rb
76
+ - lib/mini_magick/tool/stream.rb
105
77
  - lib/mini_magick/utilities.rb
106
78
  - lib/mini_magick/version.rb
107
- - spec/files/actually_a_gif.jpg
108
- - spec/files/animation.gif
109
- - spec/files/composited.jpg
110
- - spec/files/erroneous.jpg
111
- - spec/files/layers.psd
112
- - spec/files/leaves (spaced).tiff
113
- - spec/files/not_an_image.php
114
- - spec/files/png.png
115
- - spec/files/simple-minus.gif
116
- - spec/files/simple.gif
117
- - spec/files/trogdor.jpg
118
- - spec/files/trogdor_capitalized.JPG
119
- - spec/lib/mini_magick/command_builder_spec.rb
79
+ - spec/fixtures/animation.gif
80
+ - spec/fixtures/default.jpg
81
+ - spec/fixtures/exif.jpg
82
+ - spec/fixtures/image.psd
83
+ - spec/fixtures/not_an_image.rb
84
+ - spec/lib/mini_magick/configuration_spec.rb
120
85
  - spec/lib/mini_magick/image_spec.rb
86
+ - spec/lib/mini_magick/shell_spec.rb
87
+ - spec/lib/mini_magick/tool_spec.rb
88
+ - spec/lib/mini_magick/utilities_spec.rb
121
89
  - spec/lib/mini_magick_spec.rb
122
90
  - spec/spec_helper.rb
91
+ - spec/support/helpers.rb
123
92
  homepage: https://github.com/minimagick/minimagick
124
93
  licenses:
125
94
  - MIT
@@ -135,9 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
104
  version: '0'
136
105
  required_rubygems_version: !ruby/object:Gem::Requirement
137
106
  requirements:
138
- - - ">="
107
+ - - ">"
139
108
  - !ruby/object:Gem::Version
140
- version: '0'
109
+ version: 1.3.1
141
110
  requirements:
142
111
  - You must have ImageMagick or GraphicsMagick installed
143
112
  rubyforge_project:
@@ -146,19 +115,16 @@ signing_key:
146
115
  specification_version: 4
147
116
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
148
117
  test_files:
149
- - spec/files/actually_a_gif.jpg
150
- - spec/files/animation.gif
151
- - spec/files/composited.jpg
152
- - spec/files/erroneous.jpg
153
- - spec/files/layers.psd
154
- - spec/files/leaves (spaced).tiff
155
- - spec/files/not_an_image.php
156
- - spec/files/png.png
157
- - spec/files/simple-minus.gif
158
- - spec/files/simple.gif
159
- - spec/files/trogdor.jpg
160
- - spec/files/trogdor_capitalized.JPG
161
- - spec/lib/mini_magick/command_builder_spec.rb
118
+ - spec/fixtures/animation.gif
119
+ - spec/fixtures/default.jpg
120
+ - spec/fixtures/exif.jpg
121
+ - spec/fixtures/image.psd
122
+ - spec/fixtures/not_an_image.rb
123
+ - spec/lib/mini_magick/configuration_spec.rb
162
124
  - spec/lib/mini_magick/image_spec.rb
125
+ - spec/lib/mini_magick/shell_spec.rb
126
+ - spec/lib/mini_magick/tool_spec.rb
127
+ - spec/lib/mini_magick/utilities_spec.rb
163
128
  - spec/lib/mini_magick_spec.rb
164
129
  - spec/spec_helper.rb
130
+ - spec/support/helpers.rb