mini_magick 4.12.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,13 @@ require "mini_magick/shell"
2
2
 
3
3
  module MiniMagick
4
4
  ##
5
- # Abstract class that wraps command-line tools. It shouldn't be used directly,
6
- # but through one of its subclasses (e.g. {MiniMagick::Tool::Mogrify}). Use
7
- # this class if you want to be closer to the metal and execute ImageMagick
8
- # commands directly, but still with a nice Ruby interface.
5
+ # Class that wraps command-line tools directly, as opposed MiniMagick::Image
6
+ # which is more high-level.
9
7
  #
10
8
  # @example
11
- # MiniMagick::Tool::Mogrify.new do |builder|
12
- # builder.resize "500x500"
13
- # builder << "path/to/image.jpg"
9
+ # MiniMagick.mogrify do |mogrify|
10
+ # mogrify.resize "500x500"
11
+ # mogrify << "path/to/image.jpg"
14
12
  # end
15
13
  #
16
14
  class Tool
@@ -23,8 +21,7 @@ module MiniMagick
23
21
  # executes the command in the end.
24
22
  #
25
23
  # @example
26
- # version = MiniMagick::Tool::Identify.new { |b| b.version }
27
- # puts version
24
+ # puts MiniMagick.identify(&:version)
28
25
  #
29
26
  # @return [MiniMagick::Tool, String] If no block is given, returns an
30
27
  # instance of the tool, if block is given, returns the output of the
@@ -46,31 +43,31 @@ module MiniMagick
46
43
 
47
44
  # @param name [String]
48
45
  # @param options [Hash]
49
- # @option options [Boolean] :whiny Whether to raise errors on non-zero
46
+ # @option options [Boolean] :errors Whether to raise errors on non-zero
50
47
  # exit codes.
48
+ # @option options [Boolean] :warnings Whether to print warnings to stderrr.
49
+ # @option options [String] :stdin Content to send to standard input stream.
51
50
  # @example
52
- # MiniMagick::Tool::Identify.new(whiny: false) do |identify|
51
+ # MiniMagick.identify(errors: false) do |identify|
53
52
  # identify.help # returns exit status 1, which would otherwise throw an error
54
53
  # end
55
- def initialize(name, options = {})
56
- warn "MiniMagick::Tool.new(false) is deprecated and will be removed in MiniMagick 5, use MiniMagick::Tool.new(whiny: false) instead." if !options.is_a?(Hash)
57
-
58
- @name = name
59
- @args = []
60
- @whiny = options.is_a?(Hash) ? options.fetch(:whiny, MiniMagick.whiny) : options
54
+ def initialize(name, **options)
55
+ @name = name
56
+ @args = []
57
+ @options = options
61
58
  end
62
59
 
63
60
  ##
64
61
  # Executes the command that has been built up.
65
62
  #
66
63
  # @example
67
- # mogrify = MiniMagick::Tool::Mogrify.new
64
+ # mogrify = MiniMagick.mogrify
68
65
  # mogrify.resize("500x500")
69
66
  # mogrify << "path/to/image.jpg"
70
67
  # mogrify.call # executes `mogrify -resize 500x500 path/to/image.jpg`
71
68
  #
72
69
  # @example
73
- # mogrify = MiniMagick::Tool::Mogrify.new
70
+ # mogrify = MiniMagick.mogrify
74
71
  # # build the command
75
72
  # mogrify.call do |stdout, stderr, status|
76
73
  # # ...
@@ -80,16 +77,12 @@ module MiniMagick
80
77
  #
81
78
  # @return [String] Returns the output of the command
82
79
  #
83
- def call(*args)
84
- options = args[-1].is_a?(Hash) ? args.pop : {}
85
- warn "Passing whiny to MiniMagick::Tool#call is deprecated and will be removed in MiniMagick 5, use MiniMagick::Tool.new(whiny: false) instead." if args.any?
86
- whiny = args.fetch(0, @whiny)
87
-
88
- options[:whiny] = whiny
89
- options[:stderr] = false if block_given?
80
+ def call(**options)
81
+ options = @options.merge(options)
82
+ options[:warnings] = false if block_given?
90
83
 
91
84
  shell = MiniMagick::Shell.new
92
- stdout, stderr, status = shell.run(command, options)
85
+ stdout, stderr, status = shell.run(command, **options)
93
86
  yield stdout, stderr, status if block_given?
94
87
 
95
88
  stdout.chomp("\n")
@@ -101,7 +94,7 @@ module MiniMagick
101
94
  # @return [Array<String>]
102
95
  #
103
96
  # @example
104
- # mogrify = MiniMagick::Tool::Mogrify.new
97
+ # mogrify = MiniMagick.mogrify
105
98
  # mogrify.resize "500x500"
106
99
  # mogrify.contrast
107
100
  # mogrify.command #=> ["mogrify", "-resize", "500x500", "-contrast"]
@@ -112,29 +105,24 @@ module MiniMagick
112
105
 
113
106
  ##
114
107
  # The executable used for this tool. Respects
115
- # {MiniMagick::Configuration#cli}, {MiniMagick::Configuration#cli_path},
116
- # and {MiniMagick::Configuration#cli_prefix}.
108
+ # {MiniMagick::Configuration#cli_prefix}.
117
109
  #
118
110
  # @return [Array<String>]
119
111
  #
120
112
  # @example
121
- # MiniMagick.configure { |config| config.cli = :graphicsmagick }
122
- # identify = MiniMagick::Tool::Identify.new
123
- # identify.executable #=> ["gm", "identify"]
113
+ # identify = MiniMagick.identify
114
+ # identify.executable #=> ["magick", "identify"]
124
115
  #
125
116
  # @example
126
117
  # MiniMagick.configure do |config|
127
- # config.cli = :graphicsmagick
128
118
  # config.cli_prefix = ['firejail', '--force']
129
119
  # end
130
- # identify = MiniMagick::Tool::Identify.new
131
- # identify.executable #=> ["firejail", "--force", "gm", "identify"]
120
+ # identify = MiniMagick.identify
121
+ # identify.executable #=> ["firejail", "--force", "magick", "identify"]
132
122
  #
133
123
  def executable
134
124
  exe = [name]
135
125
  exe.unshift "magick" if MiniMagick.imagemagick7? && name != "magick"
136
- exe.unshift "gm" if MiniMagick.graphicsmagick?
137
- exe.unshift File.join(MiniMagick.cli_path, exe.shift) if MiniMagick.cli_path
138
126
  Array(MiniMagick.cli_prefix).reverse_each { |p| exe.unshift p } if MiniMagick.cli_prefix
139
127
  exe
140
128
  end
@@ -163,7 +151,7 @@ module MiniMagick
163
151
  # Changes the last operator to its "plus" form.
164
152
  #
165
153
  # @example
166
- # MiniMagick::Tool::Mogrify.new do |mogrify|
154
+ # MiniMagick.mogrify do |mogrify|
167
155
  # mogrify.antialias.+
168
156
  # mogrify.distort.+("Perspective", "0,0,4,5 89,0,45,46")
169
157
  # end
@@ -181,7 +169,7 @@ module MiniMagick
181
169
  # Create an ImageMagick stack in the command (surround.
182
170
  #
183
171
  # @example
184
- # MiniMagick::Tool::Convert.new do |convert|
172
+ # MiniMagick.convert do |convert|
185
173
  # convert << "wand.gif"
186
174
  # convert.stack do |stack|
187
175
  # stack << "wand.gif"
@@ -208,7 +196,7 @@ module MiniMagick
208
196
  # Adds ImageMagick's pseudo-filename `-` for standard input.
209
197
  #
210
198
  # @example
211
- # identify = MiniMagick::Tool::Identify.new
199
+ # identify = MiniMagick.identify
212
200
  # identify.stdin
213
201
  # identify.call(stdin: image_content)
214
202
  # # executes `identify -` with the given standard input
@@ -221,7 +209,7 @@ module MiniMagick
221
209
  # Adds ImageMagick's pseudo-filename `-` for standard output.
222
210
  #
223
211
  # @example
224
- # content = MiniMagick::Tool::Convert.new do |convert|
212
+ # content = MiniMagick.convert do |convert|
225
213
  # convert << "input.jpg"
226
214
  # convert.auto_orient
227
215
  # convert.stdout
@@ -273,35 +261,14 @@ module MiniMagick
273
261
  self
274
262
  end
275
263
 
276
- def self.option_methods
277
- @option_methods ||= (
278
- tool = new(whiny: false)
279
- tool << "-help"
280
- help_page = tool.call(stderr: false)
281
-
282
- cli_options = help_page.scan(/^\s+-[a-z\-]+/).map(&:strip)
283
- if tool.name == "mogrify" && MiniMagick.graphicsmagick?
284
- # These options were undocumented before 2015-06-14 (see gm bug 302)
285
- cli_options |= %w[-box -convolve -gravity -linewidth -mattecolor -render -shave]
264
+ # deprecated tool subclasses
265
+ %w[animate compare composite conjure convert display identify import magick mogrify montage stream].each do |tool|
266
+ const_set(tool.capitalize, Class.new(self) {
267
+ define_method(:initialize) do |*args|
268
+ super(tool, *args)
286
269
  end
287
-
288
- cli_options.map { |o| o[1..-1].tr('-','_') }
289
- )
270
+ })
271
+ deprecate_constant(tool.capitalize)
290
272
  end
291
-
292
273
  end
293
274
  end
294
-
295
- require "mini_magick/tool/animate"
296
- require "mini_magick/tool/compare"
297
- require "mini_magick/tool/composite"
298
- require "mini_magick/tool/conjure"
299
- require "mini_magick/tool/convert"
300
- require "mini_magick/tool/display"
301
- require "mini_magick/tool/identify"
302
- require "mini_magick/tool/import"
303
- require "mini_magick/tool/magick"
304
- require "mini_magick/tool/mogrify"
305
- require "mini_magick/tool/mogrify_restricted"
306
- require "mini_magick/tool/montage"
307
- require "mini_magick/tool/stream"
@@ -24,12 +24,10 @@ module MiniMagick
24
24
  end
25
25
 
26
26
  def tempfile(extension)
27
- Tempfile.new(["mini_magick", extension], MiniMagick.tmpdir).tap do |tempfile|
28
- tempfile.binmode
29
- yield tempfile if block_given?
30
- tempfile.close
31
- end
27
+ tempfile = Tempfile.new(["mini_magick", extension], MiniMagick.tmpdir, binmode: true)
28
+ yield tempfile if block_given?
29
+ tempfile.close
30
+ tempfile
32
31
  end
33
-
34
32
  end
35
33
  end
@@ -7,9 +7,9 @@ module MiniMagick
7
7
  end
8
8
 
9
9
  module VERSION
10
- MAJOR = 4
11
- MINOR = 12
12
- TINY = 0
10
+ MAJOR = 5
11
+ MINOR = 0
12
+ TINY = 1
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
data/lib/mini_magick.rb CHANGED
@@ -1,64 +1,39 @@
1
1
  require 'mini_magick/version'
2
2
  require 'mini_magick/configuration'
3
+ require 'mini_magick/utilities'
4
+ require 'mini_magick/tool'
5
+ require 'mini_magick/image'
3
6
 
4
7
  module MiniMagick
5
8
 
6
- extend MiniMagick::Configuration
7
-
8
- ##
9
- # You might want to execute only certain blocks of processing with a
10
- # different CLI, because for example that CLI does that particular thing
11
- # faster. After the block CLI resets to its previous value.
12
- #
13
- # @example
14
- # MiniMagick.with_cli :graphicsmagick do
15
- # # operations that are better done with GraphicsMagick
16
- # end
17
- def self.with_cli(cli)
18
- old_cli = self.cli
19
- self.cli = cli
20
- yield
21
- ensure
22
- self.cli = old_cli
23
- end
9
+ Error = Class.new(RuntimeError)
10
+ Invalid = Class.new(StandardError)
11
+ TimeoutError = Class.new(Error)
24
12
 
25
- ##
26
- # Checks whether the CLI used is ImageMagick.
27
- #
28
- # @return [Boolean]
29
- def self.imagemagick?
30
- cli == :imagemagick
31
- end
13
+ extend MiniMagick::Configuration
32
14
 
33
15
  ##
34
- # Checks whether the CLI used is ImageMagick 7.
16
+ # Checks whether ImageMagick 7 is installed.
35
17
  #
36
18
  # @return [Boolean]
37
19
  def self.imagemagick7?
38
- cli == :imagemagick7
20
+ return @imagemagick7 if defined?(@imagemagick7)
21
+ @imagemagick7 = !!MiniMagick::Utilities.which("magick")
39
22
  end
40
23
 
41
- ##
42
- # Checks whether the CLI used is GraphicsMagick.
43
- #
44
- # @return [Boolean]
45
- def self.graphicsmagick?
46
- cli == :graphicsmagick
24
+ %w[animate compare composite conjure convert display identify import mogrify montage stream].each do |tool|
25
+ define_singleton_method(tool) do |**options, &block|
26
+ name = imagemagick7? && tool == "convert" ? "magick" : tool
27
+ MiniMagick::Tool.new(name, **options, &block)
28
+ end
47
29
  end
48
30
 
49
31
  ##
50
- # Returns ImageMagick's/GraphicsMagick's version.
32
+ # Returns ImageMagick version.
51
33
  #
52
34
  # @return [String]
53
35
  def self.cli_version
54
- output = MiniMagick::Tool::Identify.new(&:version)
36
+ output = MiniMagick.identify(&:version)
55
37
  output[/\d+\.\d+\.\d+(-\d+)?/]
56
38
  end
57
-
58
- class Error < RuntimeError; end
59
- class Invalid < StandardError; end
60
-
61
39
  end
62
-
63
- require 'mini_magick/tool'
64
- require 'mini_magick/image'
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: 4.12.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2022-12-07 00:00:00.000000000 Z
16
+ date: 2024-07-24 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake
@@ -35,56 +35,14 @@ dependencies:
35
35
  requirements:
36
36
  - - "~>"
37
37
  - !ruby/object:Gem::Version
38
- version: 3.5.0
38
+ version: '3.5'
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - "~>"
44
44
  - !ruby/object:Gem::Version
45
- version: 3.5.0
46
- - !ruby/object:Gem::Dependency
47
- name: guard
48
- requirement: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: '0'
53
- type: :development
54
- prerelease: false
55
- version_requirements: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: '0'
60
- - !ruby/object:Gem::Dependency
61
- name: guard-rspec
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: '0'
67
- type: :development
68
- prerelease: false
69
- version_requirements: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: '0'
74
- - !ruby/object:Gem::Dependency
75
- name: posix-spawn
76
- requirement: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: '0'
81
- type: :development
82
- prerelease: false
83
- version_requirements: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- version: '0'
45
+ version: '3.5'
88
46
  - !ruby/object:Gem::Dependency
89
47
  name: webmock
90
48
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +57,7 @@ dependencies:
99
57
  - - ">="
100
58
  - !ruby/object:Gem::Version
101
59
  version: '0'
102
- description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
60
+ description: Manipulate images with minimal use of memory via ImageMagick
103
61
  email:
104
62
  - probablycorey@gmail.com
105
63
  - hcatlin@gmail.com
@@ -112,33 +70,21 @@ extensions: []
112
70
  extra_rdoc_files: []
113
71
  files:
114
72
  - MIT-LICENSE
73
+ - README.md
115
74
  - Rakefile
116
- - lib/mini_gmagick.rb
117
75
  - lib/mini_magick.rb
118
76
  - lib/mini_magick/configuration.rb
119
77
  - lib/mini_magick/image.rb
120
78
  - lib/mini_magick/image/info.rb
121
79
  - lib/mini_magick/shell.rb
122
80
  - lib/mini_magick/tool.rb
123
- - lib/mini_magick/tool/animate.rb
124
- - lib/mini_magick/tool/compare.rb
125
- - lib/mini_magick/tool/composite.rb
126
- - lib/mini_magick/tool/conjure.rb
127
- - lib/mini_magick/tool/convert.rb
128
- - lib/mini_magick/tool/display.rb
129
- - lib/mini_magick/tool/identify.rb
130
- - lib/mini_magick/tool/import.rb
131
- - lib/mini_magick/tool/magick.rb
132
- - lib/mini_magick/tool/mogrify.rb
133
- - lib/mini_magick/tool/mogrify_restricted.rb
134
- - lib/mini_magick/tool/montage.rb
135
- - lib/mini_magick/tool/stream.rb
136
81
  - lib/mini_magick/utilities.rb
137
82
  - lib/mini_magick/version.rb
138
83
  homepage: https://github.com/minimagick/minimagick
139
84
  licenses:
140
85
  - MIT
141
- metadata: {}
86
+ metadata:
87
+ changelog_uri: https://github.com/minimagick/minimagick/releases
142
88
  post_install_message:
143
89
  rdoc_options: []
144
90
  require_paths:
@@ -147,16 +93,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
93
  requirements:
148
94
  - - ">="
149
95
  - !ruby/object:Gem::Version
150
- version: '2.0'
96
+ version: '2.3'
151
97
  required_rubygems_version: !ruby/object:Gem::Requirement
152
98
  requirements:
153
99
  - - ">="
154
100
  - !ruby/object:Gem::Version
155
101
  version: '0'
156
102
  requirements:
157
- - You must have ImageMagick or GraphicsMagick installed
158
- rubygems_version: 3.3.3
103
+ - You must have ImageMagick installed
104
+ rubygems_version: 3.5.11
159
105
  signing_key:
160
106
  specification_version: 4
161
- summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
107
+ summary: Manipulate images with minimal use of memory via ImageMagick
162
108
  test_files: []
data/lib/mini_gmagick.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'mini_magick'
2
-
3
- MiniMagick.processor = :gm
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/animate.php
5
- #
6
- class Animate < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("animate", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/compare.php
5
- #
6
- class Compare < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("compare", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/composite.php
5
- #
6
- class Composite < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("composite", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/conjure.php
5
- #
6
- class Conjure < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("conjure", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/convert.php
5
- #
6
- class Convert < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("convert", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/display.php
5
- #
6
- class Display < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("display", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/identify.php
5
- #
6
- class Identify < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("identify", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/import.php
5
- #
6
- class Import < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("import", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/command-line-processing.php
5
- #
6
- class Magick < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("magick", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/mogrify.php
5
- #
6
- class Mogrify < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("mogrify", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- require "mini_magick/tool/mogrify"
2
-
3
- module MiniMagick
4
- class Tool
5
- ##
6
- # @see http://www.imagemagick.org/script/mogrify.php
7
- #
8
- class MogrifyRestricted < Mogrify
9
- def format(*args)
10
- fail NoMethodError,
11
- "you must call #format on a MiniMagick::Image directly"
12
- end
13
- end
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/montage.php
5
- #
6
- class Montage < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("montage", *args)
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module MiniMagick
2
- class Tool
3
- ##
4
- # @see http://www.imagemagick.org/script/stream.php
5
- #
6
- class Stream < MiniMagick::Tool
7
-
8
- def initialize(*args)
9
- super("stream", *args)
10
- end
11
-
12
- end
13
- end
14
- end