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.
@@ -17,8 +17,6 @@ module MiniMagick
17
17
  cheap_info(value)
18
18
  when "colorspace"
19
19
  colorspace
20
- when "mime_type"
21
- mime_type
22
20
  when "resolution"
23
21
  resolution(*args)
24
22
  when "signature"
@@ -27,8 +25,6 @@ module MiniMagick
27
25
  raw_exif(value)
28
26
  when "exif"
29
27
  exif
30
- when "details"
31
- details
32
28
  when "data"
33
29
  data
34
30
  else
@@ -76,12 +72,6 @@ module MiniMagick
76
72
  @info["colorspace"] ||= self["%r"]
77
73
  end
78
74
 
79
- def mime_type
80
- warn "[MiniMagick] MiniMagick::Image#mime_type has been deprecated, because it wasn't returning correct result for all formats ImageMagick supports. Unfortunately, returning the correct MIME type would be very slow, because it would require ImageMagick to read the whole file. It's better to use Marcel and MimeMagic gems, which are able to determine the MIME type just from the image header."
81
-
82
- "image/#{self["format"].downcase}"
83
- end
84
-
85
75
  def resolution(unit = nil)
86
76
  output = identify do |b|
87
77
  b.units unit if unit
@@ -102,20 +92,12 @@ module MiniMagick
102
92
  output.each_line do |line|
103
93
  line = line.chomp("\n")
104
94
 
105
- case MiniMagick.cli
106
- when :imagemagick, :imagemagick7
107
- if match = line.match(/^exif:/)
108
- key, value = match.post_match.split("=", 2)
109
- value = decode_comma_separated_ascii_characters(value) if ASCII_ENCODED_EXIF_KEYS.include?(key)
110
- hash[key] = value
111
- else
112
- hash[hash.keys.last] << "\n#{line}"
113
- end
114
- when :graphicsmagick
115
- next if line == "unknown"
116
- key, value = line.split("=", 2)
117
- value.gsub!("\\012", "\n") # convert "\012" characters to newlines
95
+ if match = line.match(/^exif:/)
96
+ key, value = match.post_match.split("=", 2)
97
+ value = decode_comma_separated_ascii_characters(value) if ASCII_ENCODED_EXIF_KEYS.include?(key)
118
98
  hash[key] = value
99
+ else
100
+ hash[hash.keys.last] << "\n#{line}"
119
101
  end
120
102
  end
121
103
 
@@ -131,44 +113,9 @@ module MiniMagick
131
113
  @info["signature"] ||= self["%#"]
132
114
  end
133
115
 
134
- def details
135
- warn "[MiniMagick] MiniMagick::Image#details has been deprecated, as it was causing too many parsing errors. You should use MiniMagick::Image#data instead, which differs in a way that the keys are in camelcase." if MiniMagick.imagemagick? || MiniMagick.imagemagick7?
136
-
137
- @info["details"] ||= (
138
- details_string = identify(&:verbose)
139
- key_stack = []
140
- details_string.lines.to_a[1..-1].each_with_object({}) do |line, details_hash|
141
- next if !line.valid_encoding? || line.strip.length.zero?
142
-
143
- level = line[/^\s*/].length / 2 - 1
144
- if level >= 0
145
- key_stack.pop until key_stack.size <= level
146
- else
147
- # Some metadata, such as SVG clipping paths, will be saved without
148
- # indentation, resulting in a level of -1
149
- last_key = details_hash.keys.last
150
- details_hash[last_key] = '' if details_hash[last_key].empty?
151
- details_hash[last_key] << line
152
- next
153
- end
154
-
155
- key, _, value = line.partition(/:[\s]/).map(&:strip)
156
- hash = key_stack.inject(details_hash) { |_hash, _key| _hash.fetch(_key) }
157
- if value.empty?
158
- hash[key] = {}
159
- key_stack.push key
160
- else
161
- hash[key] = value
162
- end
163
- end
164
- )
165
- end
166
-
167
116
  def data
168
- raise Error, "MiniMagick::Image#data isn't supported on GraphicsMagick. Use MiniMagick::Image#details instead." if MiniMagick.graphicsmagick?
169
-
170
117
  @info["data"] ||= (
171
- json = MiniMagick::Tool::Convert.new do |convert|
118
+ json = MiniMagick.convert do |convert|
172
119
  convert << path
173
120
  convert << "json:"
174
121
  end
@@ -180,7 +127,7 @@ module MiniMagick
180
127
  end
181
128
 
182
129
  def identify
183
- MiniMagick::Tool::Identify.new do |builder|
130
+ MiniMagick.identify do |builder|
184
131
  yield builder if block_given?
185
132
  builder << path
186
133
  end
@@ -51,11 +51,11 @@ module MiniMagick
51
51
  #
52
52
  def self.import_pixels(blob, columns, rows, depth, map, format = 'png')
53
53
  # Create an image object with the raw pixel data string:
54
- create(".dat", false) { |f| f.write(blob) }.tap do |image|
54
+ read(blob, ".dat").tap do |image|
55
55
  output_path = image.path.sub(/\.\w+$/, ".#{format}")
56
56
  # Use ImageMagick to convert the raw data file to an image file of the
57
57
  # desired format:
58
- MiniMagick::Tool::Convert.new do |convert|
58
+ MiniMagick.convert do |convert|
59
59
  convert.size "#{columns}x#{rows}"
60
60
  convert.depth depth
61
61
  convert << "#{map}:#{image.path}"
@@ -79,33 +79,15 @@ module MiniMagick
79
79
  # @param options [Hash] Specify options for the open method
80
80
  # @return [MiniMagick::Image] The loaded image
81
81
  #
82
- def self.open(path_or_url, ext = nil, options = {})
83
- options, ext = ext, nil if ext.is_a?(Hash)
84
-
85
- # Don't use Kernel#open, but reuse its logic
86
- openable =
87
- if path_or_url.respond_to?(:open)
88
- path_or_url
89
- elsif path_or_url.respond_to?(:to_str) &&
90
- %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ path_or_url &&
91
- (uri = URI.parse(path_or_url)).respond_to?(:open)
92
- uri
93
- else
94
- options = { binmode: true }.merge(options)
95
- Pathname(path_or_url)
96
- end
97
-
98
- if openable.is_a?(URI::Generic)
99
- ext ||= File.extname(openable.path)
100
- else
101
- ext ||= File.extname(openable.to_s)
102
- end
103
- ext.sub!(/:.*/, '') # hack for filenames or URLs that include a colon
104
-
105
- if openable.is_a?(URI::Generic)
106
- openable.open(options) { |file| read(file, ext) }
82
+ def self.open(path_or_url, ext = nil, **options)
83
+ if path_or_url.to_s =~ %r{\A(https?|ftp)://}
84
+ uri = URI(path_or_url)
85
+ ext ||= File.extname(uri.path).sub(/:.*/, '') # handle URL including a colon
86
+ uri.open(options) { |file| read(file, ext) }
107
87
  else
108
- openable.open(**options) { |file| read(file, ext) }
88
+ pathname = Pathname(path_or_url)
89
+ ext ||= File.extname(pathname.to_s)
90
+ pathname.open(binmode: true, **options) { |file| read(file, ext) }
109
91
  end
110
92
  end
111
93
 
@@ -118,18 +100,14 @@ module MiniMagick
118
100
  # we have a good tempfile.
119
101
  #
120
102
  # @param ext [String] Specify the extension you want to read it as
121
- # @param validate [Boolean] If false, skips validation of the created
122
- # image. Defaults to true.
123
103
  # @yield [Tempfile] You can #write bits to this object to create the new
124
104
  # Image
125
105
  # @return [MiniMagick::Image] The created image
126
106
  #
127
- def self.create(ext = nil, validate = MiniMagick.validate_on_create, &block)
107
+ def self.create(ext = nil, &block)
128
108
  tempfile = MiniMagick::Utilities.tempfile(ext.to_s.downcase, &block)
129
109
 
130
- new(tempfile.path, tempfile).tap do |image|
131
- image.validate! if validate
132
- end
110
+ new(tempfile.path, tempfile)
133
111
  end
134
112
 
135
113
  ##
@@ -164,7 +142,7 @@ module MiniMagick
164
142
  # which creates a temporary file for you and protects your original.
165
143
  #
166
144
  # @param input_path [String, Pathname] The location of an image file
167
- # @yield [MiniMagick::Tool::Mogrify] If block is given, {#combine_options}
145
+ # @yield [MiniMagick::Tool] If block is given, {#combine_options}
168
146
  # is called.
169
147
  #
170
148
  def initialize(input_path, tempfile = nil, &block)
@@ -228,10 +206,6 @@ module MiniMagick
228
206
  #
229
207
  attribute :type, "format"
230
208
  ##
231
- # @return [String]
232
- #
233
- attribute :mime_type
234
- ##
235
209
  # @return [Integer]
236
210
  #
237
211
  attribute :width
@@ -286,17 +260,10 @@ module MiniMagick
286
260
  #
287
261
  attribute :signature
288
262
  ##
289
- # Returns the information from `identify -verbose` in a Hash format, for
290
- # ImageMagick.
263
+ # Returns the result of converting the image to JSON format.
291
264
  #
292
265
  # @return [Hash]
293
266
  attribute :data
294
- ##
295
- # Returns the information from `identify -verbose` in a Hash format, for
296
- # GraphicsMagick.
297
- #
298
- # @return [Hash]
299
- attribute :details
300
267
 
301
268
  ##
302
269
  # Use this method if you want to access raw Identify's format API.
@@ -367,7 +334,7 @@ module MiniMagick
367
334
  # @return [Array] Matrix of each color of each pixel
368
335
  def get_pixels(map="RGB")
369
336
  raise ArgumentError, "Invalid map value" unless ["RGB", "RGBA"].include?(map)
370
- convert = MiniMagick::Tool::Convert.new
337
+ convert = MiniMagick.convert
371
338
  convert << path
372
339
  convert.depth(8)
373
340
  convert << "#{map}:-"
@@ -397,10 +364,10 @@ module MiniMagick
397
364
  # @example
398
365
  # # It is given in readme.md file
399
366
  ##
400
- def self.get_image_from_pixels(pixels, dimension, map, depth, mime_type)
367
+ def self.get_image_from_pixels(pixels, dimension, map, depth, format)
401
368
  pixels = pixels.flatten
402
369
  blob = pixels.pack('C*')
403
- import_pixels(blob, *dimension, depth, map, mime_type)
370
+ import_pixels(blob, *dimension, depth, map, format)
404
371
  end
405
372
 
406
373
  ##
@@ -426,7 +393,7 @@ module MiniMagick
426
393
  # will convert all pages.
427
394
  # @param read_opts [Hash] Any read options to be passed to ImageMagick
428
395
  # for example: image.format('jpg', page, {density: '300'})
429
- # @yield [MiniMagick::Tool::Convert] It optionally yields the command,
396
+ # @yield [MiniMagick::Tool] It optionally yields the command,
430
397
  # if you want to add something.
431
398
  # @return [self]
432
399
  #
@@ -441,7 +408,7 @@ module MiniMagick
441
408
  input_path = path.dup
442
409
  input_path << "[#{page}]" if page && !layer?
443
410
 
444
- MiniMagick::Tool::Convert.new do |convert|
411
+ MiniMagick.convert do |convert|
445
412
  read_opts.each do |opt, val|
446
413
  convert.send(opt.to_s, val)
447
414
  end
@@ -477,7 +444,7 @@ module MiniMagick
477
444
  # c.background "blue"
478
445
  # end
479
446
  #
480
- # @yield [MiniMagick::Tool::Mogrify]
447
+ # @yield [MiniMagick::Command]
481
448
  # @see http://www.imagemagick.org/script/mogrify.php
482
449
  # @return [self]
483
450
  #
@@ -498,8 +465,11 @@ module MiniMagick
498
465
  end
499
466
  end
500
467
 
501
- def respond_to_missing?(method_name, include_private = false)
502
- MiniMagick::Tool::Mogrify.option_methods.include?(method_name.to_s)
468
+ ##
469
+ # Prevents ruby from calling `#to_ary` on the image when checking if it's a
470
+ # splattable data structure in certain cases.
471
+ def respond_to_missing?(name, include_all)
472
+ false
503
473
  end
504
474
 
505
475
  ##
@@ -514,7 +484,7 @@ module MiniMagick
514
484
  case output_to
515
485
  when String, Pathname
516
486
  if layer?
517
- MiniMagick::Tool::Convert.new do |builder|
487
+ MiniMagick.convert do |builder|
518
488
  builder << path
519
489
  builder << output_to
520
490
  end
@@ -541,7 +511,7 @@ module MiniMagick
541
511
  def composite(other_image, output_extension = type.downcase, mask = nil)
542
512
  output_tempfile = MiniMagick::Utilities.tempfile(".#{output_extension}")
543
513
 
544
- MiniMagick::Tool::Composite.new do |composite|
514
+ MiniMagick.composite do |composite|
545
515
  yield composite if block_given?
546
516
  composite << other_image.path
547
517
  composite << path
@@ -583,27 +553,21 @@ module MiniMagick
583
553
  # b.verbose
584
554
  # end # runs `identify -verbose image.jpg`
585
555
  # @return [String] Output from `identify`
586
- # @yield [MiniMagick::Tool::Identify]
556
+ # @yield [MiniMagick::Tool]
587
557
  #
588
558
  def identify
589
- MiniMagick::Tool::Identify.new do |builder|
559
+ MiniMagick.identify do |builder|
590
560
  yield builder if block_given?
591
561
  builder << path
592
562
  end
593
563
  end
594
564
 
595
- # @private
596
- def run_command(tool_name, *args)
597
- MiniMagick::Tool.const_get(tool_name.capitalize).new do |builder|
598
- args.each do |arg|
599
- builder << arg
600
- end
601
- end
602
- end
603
-
604
565
  def mogrify(page = nil)
605
- MiniMagick::Tool::MogrifyRestricted.new do |builder|
566
+ MiniMagick.mogrify do |builder|
606
567
  yield builder if block_given?
568
+ if builder.args.include?("-format")
569
+ fail MiniMagick::Error, "you must call #format on a MiniMagick::Image directly"
570
+ end
607
571
  builder << (page ? "#{path}[#{page}]" : path)
608
572
  end
609
573
 
@@ -1,4 +1,4 @@
1
- require "timeout"
1
+ require "open3"
2
2
  require "benchmark"
3
3
 
4
4
  module MiniMagick
@@ -10,24 +10,30 @@ module MiniMagick
10
10
  #
11
11
  class Shell
12
12
 
13
- def run(command, options = {})
14
- stdout, stderr, status = execute(command, stdin: options[:stdin])
13
+ def run(command, errors: MiniMagick.errors, warnings: MiniMagick.warnings, **options)
14
+ stdout, stderr, status = execute(command, **options)
15
15
 
16
- if status != 0 && options.fetch(:whiny, MiniMagick.whiny)
17
- fail MiniMagick::Error, "`#{command.join(" ")}` failed with status: #{status.inspect} and error:\n#{stderr}"
16
+ if status != 0
17
+ if stderr.include?("time limit exceeded")
18
+ fail MiniMagick::TimeoutError, "`#{command.join(" ")}` has timed out"
19
+ elsif errors
20
+ fail MiniMagick::Error, "`#{command.join(" ")}` failed with status: #{status.inspect} and error:\n#{stderr}"
21
+ end
18
22
  end
19
23
 
20
- stderr = stderr.lines[2..-1].join if stderr.start_with? %(WARNING: The convert command is deprecated in IMv7)
21
- $stderr.print(stderr) unless options[:stderr] == false
24
+ $stderr.print(stderr) if warnings
22
25
 
23
26
  [stdout, stderr, status]
24
27
  end
25
28
 
26
- def execute(command, options = {})
27
- stdout, stderr, status =
28
- log(command.join(" ")) do
29
- send("execute_#{MiniMagick.shell_api.tr("-", "_")}", command, options)
30
- end
29
+ def execute(command, stdin: "", timeout: MiniMagick.timeout)
30
+ env = {}
31
+ env.merge!(MiniMagick.cli_env)
32
+ env["MAGICK_TIME_LIMIT"] = timeout.to_s if timeout
33
+
34
+ stdout, stderr, status = log(command.join(" ")) do
35
+ Open3.capture3(env, *command, stdin_data: stdin)
36
+ end
31
37
 
32
38
  [stdout, stderr, status&.exitstatus]
33
39
  rescue Errno::ENOENT, IOError
@@ -36,39 +42,6 @@ module MiniMagick
36
42
 
37
43
  private
38
44
 
39
- def execute_open3(command, options = {})
40
- require "open3"
41
-
42
- # We would ideally use Open3.capture3, but it wouldn't allow us to
43
- # terminate the command after timing out.
44
- Open3.popen3(*command) do |in_w, out_r, err_r, thread|
45
- [in_w, out_r, err_r].each(&:binmode)
46
- stdout_reader = Thread.new { out_r.read }
47
- stderr_reader = Thread.new { err_r.read }
48
- begin
49
- in_w.write options[:stdin].to_s
50
- rescue Errno::EPIPE
51
- end
52
- in_w.close
53
-
54
- unless thread.join(MiniMagick.timeout)
55
- Process.kill("TERM", thread.pid) rescue nil
56
- Process.waitpid(thread.pid) rescue nil
57
- raise Timeout::Error, "MiniMagick command timed out: #{command}"
58
- end
59
-
60
- [stdout_reader.value, stderr_reader.value, thread.value]
61
- end
62
- end
63
-
64
- def execute_posix_spawn(command, options = {})
65
- require "posix-spawn"
66
- child = POSIX::Spawn::Child.new(*command, input: options[:stdin].to_s, timeout: MiniMagick.timeout)
67
- [child.out, child.err, child.status]
68
- rescue POSIX::Spawn::TimeoutExceeded
69
- raise Timeout::Error, "MiniMagick command timed out: #{command}"
70
- end
71
-
72
45
  def log(command, &block)
73
46
  value = nil
74
47
  duration = Benchmark.realtime { value = block.call }
@@ -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] = MiniMagick.warnings && !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,30 +105,26 @@ 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]
125
+ exe.unshift "gm" if MiniMagick.graphicsmagick
135
126
  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
- Array(MiniMagick.cli_prefix).reverse_each { |p| exe.unshift p } if MiniMagick.cli_prefix
127
+ exe.unshift *Array(MiniMagick.cli_prefix)
139
128
  exe
140
129
  end
141
130
 
@@ -163,7 +152,7 @@ module MiniMagick
163
152
  # Changes the last operator to its "plus" form.
164
153
  #
165
154
  # @example
166
- # MiniMagick::Tool::Mogrify.new do |mogrify|
155
+ # MiniMagick.mogrify do |mogrify|
167
156
  # mogrify.antialias.+
168
157
  # mogrify.distort.+("Perspective", "0,0,4,5 89,0,45,46")
169
158
  # end
@@ -181,7 +170,7 @@ module MiniMagick
181
170
  # Create an ImageMagick stack in the command (surround.
182
171
  #
183
172
  # @example
184
- # MiniMagick::Tool::Magick.new do |convert|
173
+ # MiniMagick.convert do |convert|
185
174
  # convert << "wand.gif"
186
175
  # convert.stack do |stack|
187
176
  # stack << "wand.gif"
@@ -208,7 +197,7 @@ module MiniMagick
208
197
  # Adds ImageMagick's pseudo-filename `-` for standard input.
209
198
  #
210
199
  # @example
211
- # identify = MiniMagick::Tool::Identify.new
200
+ # identify = MiniMagick.identify
212
201
  # identify.stdin
213
202
  # identify.call(stdin: image_content)
214
203
  # # executes `identify -` with the given standard input
@@ -221,7 +210,7 @@ module MiniMagick
221
210
  # Adds ImageMagick's pseudo-filename `-` for standard output.
222
211
  #
223
212
  # @example
224
- # content = MiniMagick::Tool::Magick.new do |convert|
213
+ # content = MiniMagick.convert do |convert|
225
214
  # convert << "input.jpg"
226
215
  # convert.auto_orient
227
216
  # convert.stdout
@@ -273,35 +262,14 @@ module MiniMagick
273
262
  self
274
263
  end
275
264
 
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]
265
+ # deprecated tool subclasses
266
+ %w[animate compare composite conjure convert display identify import magick mogrify montage stream].each do |tool|
267
+ const_set(tool.capitalize, Class.new(self) {
268
+ define_method(:initialize) do |*args|
269
+ super(tool, *args)
286
270
  end
287
-
288
- cli_options.map { |o| o[1..-1].tr('-','_') }
289
- )
271
+ })
272
+ deprecate_constant(tool.capitalize)
290
273
  end
291
-
292
274
  end
293
275
  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,8 +7,8 @@ module MiniMagick
7
7
  end
8
8
 
9
9
  module VERSION
10
- MAJOR = 4
11
- MINOR = 13
10
+ MAJOR = 5
11
+ MINOR = 1
12
12
  TINY = 2
13
13
  PRE = nil
14
14