mini_magick 3.8.0 → 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.
Files changed (38) 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 +104 -0
  5. data/lib/mini_magick/image.rb +384 -345
  6. data/lib/mini_magick/logger.rb +40 -0
  7. data/lib/mini_magick/shell.rb +46 -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 +233 -0
  20. data/lib/mini_magick/utilities.rb +25 -26
  21. data/lib/mini_magick/version.rb +15 -1
  22. data/lib/mini_magick.rb +43 -79
  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 +407 -0
  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 +39 -0
  34. data/spec/spec_helper.rb +21 -0
  35. data/spec/support/helpers.rb +37 -0
  36. metadata +52 -54
  37. data/lib/mini_magick/command_builder.rb +0 -110
  38. data/lib/mini_magick/errors.rb +0 -4
@@ -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
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
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
8
+ end
9
+
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
13
+ end
14
+ end
15
+
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
20
+ end
21
+
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
25
+ end
26
+ end
27
+
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+$/)
32
+ end
33
+
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+$/)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require "bundler/setup"
2
+ require "mini_magick"
3
+ require "pry"
4
+
5
+ require_relative "support/helpers"
6
+
7
+ RSpec.configure do |config|
8
+ config.disable_monkey_patching!
9
+ config.formatter = "documentation"
10
+ config.color = true
11
+ config.fail_fast = true unless ENV["CI"]
12
+
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.0
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-07-22 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,49 +28,21 @@ 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
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: '0'
73
- - !ruby/object:Gem::Dependency
74
- name: mocha
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
35
+ - - "~>"
78
36
  - !ruby/object:Gem::Version
79
- version: '0'
37
+ version: 3.1.0
80
38
  type: :development
81
39
  prerelease: false
82
40
  version_requirements: !ruby/object:Gem::Requirement
83
41
  requirements:
84
- - - ">="
42
+ - - "~>"
85
43
  - !ruby/object:Gem::Version
86
- version: '0'
87
- description:
44
+ version: 3.1.0
45
+ description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
88
46
  email:
89
47
  - probablycorey@gmail.com
90
48
  - hcatlin@gmail.com
@@ -99,11 +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
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
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
89
+ - spec/lib/mini_magick_spec.rb
90
+ - spec/spec_helper.rb
91
+ - spec/support/helpers.rb
107
92
  homepage: https://github.com/minimagick/minimagick
108
93
  licenses:
109
94
  - MIT
@@ -119,9 +104,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
104
  version: '0'
120
105
  required_rubygems_version: !ruby/object:Gem::Requirement
121
106
  requirements:
122
- - - ">="
107
+ - - ">"
123
108
  - !ruby/object:Gem::Version
124
- version: '0'
109
+ version: 1.3.1
125
110
  requirements:
126
111
  - You must have ImageMagick or GraphicsMagick installed
127
112
  rubyforge_project:
@@ -129,4 +114,17 @@ rubygems_version: 2.2.2
129
114
  signing_key:
130
115
  specification_version: 4
131
116
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
132
- test_files: []
117
+ test_files:
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
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
128
+ - spec/lib/mini_magick_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/helpers.rb
@@ -1,110 +0,0 @@
1
- module MiniMagick
2
- class CommandBuilder
3
- MOGRIFY_COMMANDS = %w(adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append attenuate authenticate auto-gamma auto-level auto-orient backdrop background bench bias black-point-compensation black-threshold blend blue-primary blue-shift blur border bordercolor borderwidth brightness-contrast cache caption cdl channel charcoal chop clamp clip clip-mask clip-path clone clut coalesce colorize colormap color-matrix colors colorspace combine comment compose composite compress contrast contrast-stretch convolve crop cycle debug decipher deconstruct define delay delete density depth descend deskew despeckle direction displace display dispose dissimilarity-threshold dissolve distort dither draw duplicate edge emboss encipher encoding endian enhance equalize evaluate evaluate-sequence extent extract family features fft fill filter flatten flip floodfill flop font foreground format frame function fuzz fx gamma gaussian-blur geometry gravity green-primary hald-clut help highlight-color iconGeometry iconic identify ift immutable implode insert intent interlace interpolate interline-spacing interword-spacing kerning label lat layers level level-colors limit linear-stretch linewidth liquid-rescale list log loop lowlight-color magnify map mask mattecolor median metric mode modulate monitor monochrome morph morphology mosaic motion-blur name negate noise normalize opaque ordered-dither orient page paint path pause pen perceptible ping pointsize polaroid poly posterize precision preview print process profile quality quantize quiet radial-blur raise random-threshold red-primary regard-warnings region remap remote render repage resample resize respect-parentheses reverse roll rotate sample sampling-factor scale scene screen seed segment selective-blur separate sepia-tone set shade shadow shared-memory sharpen shave shear sigmoidal-contrast silent size sketch smush snaps solarize sparse-color splice spread statistic stegano stereo stretch strip stroke strokewidth style subimage-search swap swirl synchronize taint text-font texture threshold thumbnail tile tile-offset tint title transform transparent transparent-color transpose transverse treedepth trim type undercolor unique-colors units unsharp update verbose version view vignette virtual-pixel visual watermark wave weight white-point white-threshold window window-group write)
4
- IMAGE_CREATION_OPERATORS = %w(canvas caption gradient label logo pattern plasma radial radient rose text tile xc)
5
-
6
- def initialize(tool, *options)
7
- @tool = tool
8
- @args = []
9
- options.each { |arg| push(arg) }
10
- end
11
-
12
- def command
13
- com = "#{@tool} #{args.join(' ')}".strip
14
- com = "#{MiniMagick.processor} #{com}" unless MiniMagick.mogrify?
15
-
16
- com = File.join MiniMagick.processor_path, com unless MiniMagick.processor_path.nil?
17
- com.strip
18
- end
19
-
20
- def args
21
- if !MiniMagick::Utilities.windows?
22
- @args.map(&:shellescape)
23
- else
24
- @args.map { |arg| Utilities.windows_escape(arg) }
25
- end
26
- end
27
-
28
- # Add each mogrify command in both underscore and dash format
29
- MOGRIFY_COMMANDS.each do |mogrify_command|
30
-
31
- # Example of what is generated here:
32
- #
33
- # def auto_orient(*options)
34
- # add_command("auto-orient", *options)
35
- # self
36
- # end
37
- # alias_method :"auto-orient", :auto_orient
38
-
39
- dashed_command = mogrify_command.to_s.gsub('_', '-')
40
- underscored_command = mogrify_command.to_s.gsub('-', '_')
41
-
42
- define_method(underscored_command) do |*options|
43
- options[1] = Utilities.windows_escape(options[1]) if mogrify_command == 'annotate'
44
- add_command(__method__.to_s.gsub('_', '-'), *options)
45
- self
46
- end
47
-
48
- alias_method dashed_command, underscored_command
49
- alias_method "mogrify_#{underscored_command}", underscored_command
50
- end
51
-
52
- def format(*options)
53
- fail Error, "You must call 'format' on the image object directly!"
54
- end
55
-
56
- IMAGE_CREATION_OPERATORS.each do |operator|
57
- define_method operator do |*options|
58
- add_creation_operator(__method__.to_s, *options)
59
- self
60
- end
61
-
62
- alias_method "operator_#{operator}", operator
63
- end
64
-
65
- (MOGRIFY_COMMANDS & IMAGE_CREATION_OPERATORS).each do |command_or_operator|
66
- define_method command_or_operator do |*options|
67
- if @tool == 'mogrify'
68
- method = self.method("mogrify_#{command_or_operator}")
69
- else
70
- method = self.method("operator_#{command_or_operator}")
71
- end
72
- method.call(*options)
73
- end
74
-
75
- end
76
-
77
- def +(*options)
78
- push(@args.pop.gsub(/^-/, '+'))
79
- if options.any?
80
- options.each do |o|
81
- push o
82
- end
83
- end
84
- end
85
-
86
- def add_command(command, *options)
87
- push "-#{command}"
88
- if options.any?
89
- options.each do |o|
90
- push o
91
- end
92
- end
93
- end
94
-
95
- def add_creation_operator(command, *options)
96
- creation_command = command
97
- if options.any?
98
- options.each do |option|
99
- creation_command << ":#{option}"
100
- end
101
- end
102
- push creation_command
103
- end
104
-
105
- def push(arg)
106
- @args << arg.to_s.strip
107
- end
108
- alias_method :<<, :push
109
- end
110
- end
@@ -1,4 +0,0 @@
1
- module MiniMagick
2
- class Error < RuntimeError; end
3
- class Invalid < StandardError; end
4
- end