mini_magick 4.8.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 49a53e90d9387b9fa7dbb83e10e08fcc7650e2e8
4
- data.tar.gz: af2fecfe830084869b34bd41b6b2077b5ec4218a
2
+ SHA256:
3
+ metadata.gz: ec4d1852a0e65227776a89740f0ba57fe4925e41806387fc194492f825c9f5ea
4
+ data.tar.gz: 5263d3061216db6852a0b89d9b2ab0c32f05fcd9b685bf1aca125d41d52c714a
5
5
  SHA512:
6
- metadata.gz: fa011122b74d076892ae48198f56b71ab809f20bdca8d56c1a0754ccd7711c03093bcd6721b6b15aedd4599ede040ccb3d23d4947dbf4748f7531b5e68f0e5bb
7
- data.tar.gz: 2507b667f71982f46c181a4b0ae8c55f94a2d01338f035a98e0df38ff18639b39a957bbd754c6b481e61c0a95f446e16e157e4b9562c1551f2696651c7ef22f0
6
+ metadata.gz: 12b052fb0879fe8e3d59d6f626ff5690f26795bf8a23b7990ba86fc74382c103f8582760dbae26d8910c7e6877d853fbea13ebf3c93e524f93901cb57635935c
7
+ data.tar.gz: 5f5fda33afe5326356f3d9f2930160559b5bbe372528313c4ecebfad91a1de86edb9f2503426c0cff96035430a7a6c83a24b79174b520ecd55c31ce880eb49f1
@@ -30,6 +30,14 @@ module MiniMagick
30
30
  cli == :imagemagick
31
31
  end
32
32
 
33
+ ##
34
+ # Checks whether the CLI used is ImageMagick 7.
35
+ #
36
+ # @return [Boolean]
37
+ def self.imagemagick7?
38
+ cli == :imagemagick7
39
+ end
40
+
33
41
  ##
34
42
  # Checks whether the CLI used is GraphicsMagick.
35
43
  #
@@ -8,7 +8,7 @@ module MiniMagick
8
8
  # Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
9
9
  # [GraphicsMagick](http://www.graphicsmagick.org).
10
10
  #
11
- # @return [Symbol] `:imagemagick` or `:graphicsmagick`
11
+ # @return [Symbol] `:imagemagick`, `:imagemagick7`, or `:graphicsmagick`
12
12
  #
13
13
  attr_accessor :cli
14
14
  # @private (for backwards compatibility)
@@ -24,6 +24,17 @@ module MiniMagick
24
24
  # @private (for backwards compatibility)
25
25
  attr_accessor :processor_path
26
26
 
27
+ ##
28
+ # Adds a prefix to the CLI command.
29
+ # For example, you could use `firejail` to run all commands in a sandbox.
30
+ # Can be a string, or an array of strings.
31
+ # e.g. 'firejail', or ['firejail', '--force']
32
+ #
33
+ # @return [String]
34
+ # @return [Array<String>]
35
+ #
36
+ attr_accessor :cli_prefix
37
+
27
38
  ##
28
39
  # If you don't want commands to take too long, you can set a timeout (in
29
40
  # seconds).
@@ -102,8 +113,14 @@ module MiniMagick
102
113
  yield self
103
114
  end
104
115
 
116
+ CLI_DETECTION = {
117
+ imagemagick: "mogrify",
118
+ graphicsmagick: "gm",
119
+ imagemagick7: "magick",
120
+ }
121
+
105
122
  def processor
106
- @processor ||= ["mogrify", "gm"].detect do |processor|
123
+ @processor ||= CLI_DETECTION.values.detect do |processor|
107
124
  MiniMagick::Utilities.which(processor)
108
125
  end
109
126
  end
@@ -111,29 +128,24 @@ module MiniMagick
111
128
  def processor=(processor)
112
129
  @processor = processor.to_s
113
130
 
114
- unless ["mogrify", "gm"].include?(@processor)
131
+ unless CLI_DETECTION.value?(@processor)
115
132
  raise ArgumentError,
116
- "processor has to be set to either \"mogrify\" or \"gm\"" \
133
+ "processor has to be set to either \"magick\", \"mogrify\" or \"gm\"" \
117
134
  ", was set to #{@processor.inspect}"
118
135
  end
119
136
  end
120
137
 
121
138
  def cli
122
- @cli ||
123
- case processor.to_s
124
- when "mogrify" then :imagemagick
125
- when "gm" then :graphicsmagick
126
- else
127
- raise MiniMagick::Error, "ImageMagick/GraphicsMagick is not installed"
128
- end
139
+ @cli || CLI_DETECTION.key(processor) or
140
+ fail MiniMagick::Error, "You must have ImageMagick or GraphicsMagick installed"
129
141
  end
130
142
 
131
143
  def cli=(value)
132
144
  @cli = value
133
145
 
134
- if not [:imagemagick, :graphicsmagick].include?(@cli)
146
+ if not CLI_DETECTION.key?(@cli)
135
147
  raise ArgumentError,
136
- "CLI has to be set to either :imagemagick or :graphicsmagick" \
148
+ "CLI has to be set to either :imagemagick, :imagemagick7 or :graphicsmagick" \
137
149
  ", was set to #{@cli.inspect}"
138
150
  end
139
151
  end
@@ -100,6 +100,7 @@ module MiniMagick
100
100
  hash[hash.keys.last] << "\n#{line}"
101
101
  end
102
102
  when :graphicsmagick
103
+ next if line == "unknown"
103
104
  key, value = line.split("=", 2)
104
105
  value.gsub!("\\012", "\n") # convert "\012" characters to newlines
105
106
  hash[key] = value
@@ -139,8 +140,8 @@ module MiniMagick
139
140
  next
140
141
  end
141
142
 
142
- key, _, value = line.partition(/:[\s\n]/).map(&:strip)
143
- hash = key_stack.inject(details_hash) { |hash, key| hash.fetch(key) }
143
+ key, _, value = line.partition(/:[\s]/).map(&:strip)
144
+ hash = key_stack.inject(details_hash) { |h, k| h.fetch(k) }
144
145
  if value.empty?
145
146
  hash[key] = {}
146
147
  key_stack.push key
@@ -45,11 +45,10 @@ module MiniMagick
45
45
 
46
46
  def execute_posix_spawn(command, options = {})
47
47
  require "posix-spawn"
48
-
49
- pid, in_w, out_r, err_r = POSIX::Spawn.popen4(*command)
50
- subprocess_thread = Process.detach(pid)
51
-
52
- capture_command(in_w, out_r, err_r, subprocess_thread, options)
48
+ child = POSIX::Spawn::Child.new(*command, input: options[:stdin].to_s, timeout: MiniMagick.timeout)
49
+ [child.out, child.err, child.status]
50
+ rescue POSIX::Spawn::TimeoutExceeded
51
+ raise Timeout::Error
53
52
  end
54
53
 
55
54
  def capture_command(in_w, out_r, err_r, subprocess_thread, options)
@@ -66,7 +65,11 @@ module MiniMagick
66
65
 
67
66
  [stdout_reader.value, stderr_reader.value, subprocess_thread.value]
68
67
  rescue Timeout::Error => error
69
- Process.kill("TERM", subprocess_thread.pid)
68
+ begin
69
+ Process.kill("TERM", subprocess_thread.pid)
70
+ rescue Errno::ESRCH
71
+ # ignore if the PID doesn't exist
72
+ end
70
73
  raise error
71
74
  ensure
72
75
  [out_r, err_r].each(&:close)
@@ -15,10 +15,8 @@ module MiniMagick
15
15
  #
16
16
  class Tool
17
17
 
18
- CREATION_OPERATORS = %w[
19
- xc canvas logo rose gradient radial-gradient plasma pattern label caption
20
- text
21
- ]
18
+ CREATION_OPERATORS = %w[xc canvas logo rose gradient radial-gradient plasma
19
+ pattern text pango]
22
20
 
23
21
  ##
24
22
  # Aside from classic instantiation, it also accepts a block, and then
@@ -112,7 +110,8 @@ module MiniMagick
112
110
 
113
111
  ##
114
112
  # The executable used for this tool. Respects
115
- # {MiniMagick::Configuration#cli} and {MiniMagick::Configuration#cli_path}.
113
+ # {MiniMagick::Configuration#cli}, {MiniMagick::Configuration#cli_path},
114
+ # and {MiniMagick::Configuration#cli_prefix}.
116
115
  #
117
116
  # @return [Array<String>]
118
117
  #
@@ -121,10 +120,20 @@ module MiniMagick
121
120
  # identify = MiniMagick::Tool::Identify.new
122
121
  # identify.executable #=> ["gm", "identify"]
123
122
  #
123
+ # @example
124
+ # MiniMagick.configure do |config|
125
+ # config.cli = :graphicsmagick
126
+ # config.cli_prefix = ['firejail', '--force']
127
+ # end
128
+ # identify = MiniMagick::Tool::Identify.new
129
+ # identify.executable #=> ["firejail", "--force", "gm", "identify"]
130
+ #
124
131
  def executable
125
132
  exe = [name]
133
+ exe.unshift "magick" if MiniMagick.imagemagick7? && name != "magick"
126
134
  exe.unshift "gm" if MiniMagick.graphicsmagick?
127
135
  exe.unshift File.join(MiniMagick.cli_path, exe.shift) if MiniMagick.cli_path
136
+ Array(MiniMagick.cli_prefix).reverse_each { |p| exe.unshift p } if MiniMagick.cli_prefix
128
137
  exe
129
138
  end
130
139
 
@@ -285,6 +294,7 @@ require "mini_magick/tool/convert"
285
294
  require "mini_magick/tool/display"
286
295
  require "mini_magick/tool/identify"
287
296
  require "mini_magick/tool/import"
297
+ require "mini_magick/tool/magick"
288
298
  require "mini_magick/tool/mogrify"
289
299
  require "mini_magick/tool/mogrify_restricted"
290
300
  require "mini_magick/tool/montage"
@@ -0,0 +1,14 @@
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
@@ -8,7 +8,7 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 8
11
+ MINOR = 9
12
12
  TINY = 0
13
13
  PRE = nil
14
14
 
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.8.0
4
+ version: 4.9.0
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: 2017-07-06 00:00:00.000000000 Z
16
+ date: 2018-09-21 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake
@@ -128,6 +128,7 @@ files:
128
128
  - lib/mini_magick/tool/display.rb
129
129
  - lib/mini_magick/tool/identify.rb
130
130
  - lib/mini_magick/tool/import.rb
131
+ - lib/mini_magick/tool/magick.rb
131
132
  - lib/mini_magick/tool/mogrify.rb
132
133
  - lib/mini_magick/tool/mogrify_restricted.rb
133
134
  - lib/mini_magick/tool/montage.rb
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  requirements:
156
157
  - You must have ImageMagick or GraphicsMagick installed
157
158
  rubyforge_project:
158
- rubygems_version: 2.6.11
159
+ rubygems_version: 2.7.6
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick