mini_magick 4.8.0 → 4.9.0
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.
- checksums.yaml +5 -5
- data/lib/mini_magick.rb +8 -0
- data/lib/mini_magick/configuration.rb +25 -13
- data/lib/mini_magick/image/info.rb +3 -2
- data/lib/mini_magick/shell.rb +9 -6
- data/lib/mini_magick/tool.rb +15 -5
- data/lib/mini_magick/tool/magick.rb +14 -0
- data/lib/mini_magick/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ec4d1852a0e65227776a89740f0ba57fe4925e41806387fc194492f825c9f5ea
|
4
|
+
data.tar.gz: 5263d3061216db6852a0b89d9b2ab0c32f05fcd9b685bf1aca125d41d52c714a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12b052fb0879fe8e3d59d6f626ff5690f26795bf8a23b7990ba86fc74382c103f8582760dbae26d8910c7e6877d853fbea13ebf3c93e524f93901cb57635935c
|
7
|
+
data.tar.gz: 5f5fda33afe5326356f3d9f2930160559b5bbe372528313c4ecebfad91a1de86edb9f2503426c0cff96035430a7a6c83a24b79174b520ecd55c31ce880eb49f1
|
data/lib/mini_magick.rb
CHANGED
@@ -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
|
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 ||=
|
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
|
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
|
-
|
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
|
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
|
143
|
-
hash = key_stack.inject(details_hash) { |
|
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
|
data/lib/mini_magick/shell.rb
CHANGED
@@ -45,11 +45,10 @@ module MiniMagick
|
|
45
45
|
|
46
46
|
def execute_posix_spawn(command, options = {})
|
47
47
|
require "posix-spawn"
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
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)
|
data/lib/mini_magick/tool.rb
CHANGED
@@ -15,10 +15,8 @@ module MiniMagick
|
|
15
15
|
#
|
16
16
|
class Tool
|
17
17
|
|
18
|
-
CREATION_OPERATORS = %w[
|
19
|
-
|
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}
|
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"
|
data/lib/mini_magick/version.rb
CHANGED
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.
|
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:
|
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
|
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
|