mini_magick 4.4.0 → 4.5.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 +4 -4
- data/lib/mini_magick/configuration.rb +6 -3
- data/lib/mini_magick/image.rb +6 -4
- data/lib/mini_magick/shell.rb +24 -11
- data/lib/mini_magick/tool.rb +41 -12
- data/lib/mini_magick/version.rb +1 -1
- metadata +3 -4
- data/lib/mini_magick/logger.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fc96fb4e4e78fcb998445df1fd45fdcb54ff166
|
4
|
+
data.tar.gz: 4c51452698c426bf5ce84fc9e7d99f3b0eda5e6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70d1dc21bd68480aa447ccb2b271b9e36914ef796db9d4871d3fef773a5c181c27c3c5b7d741ec7507f0e5306be8740566bdae102d3b6f15a2c55cfe3055658a
|
7
|
+
data.tar.gz: e434f8e994c40ee2a6cd720584e87a52fecc1e3688a634192d2664042c71c778cbc8d147d358339b0c7d497dd976f28c57ef5c177755c7cb3326e8d0ceeca835
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mini_magick/utilities'
|
2
|
+
require 'logger'
|
2
3
|
|
3
4
|
module MiniMagick
|
4
5
|
module Configuration
|
@@ -86,6 +87,7 @@ module MiniMagick
|
|
86
87
|
base.validate_on_write = true
|
87
88
|
base.whiny = true
|
88
89
|
base.shell_api = "open3"
|
90
|
+
base.logger = Logger.new($stdout)
|
89
91
|
end
|
90
92
|
|
91
93
|
##
|
@@ -140,13 +142,14 @@ module MiniMagick
|
|
140
142
|
@cli_path || @processor_path
|
141
143
|
end
|
142
144
|
|
143
|
-
def
|
144
|
-
|
145
|
+
def debug=(value)
|
146
|
+
warn "MiniMagick.debug is deprecated and will be removed in MiniMagick 5. Use `MiniMagick.logger.level = Logger::DEBUG` instead."
|
147
|
+
logger.level = Logger::DEBUG
|
145
148
|
end
|
146
149
|
|
147
150
|
# Backwards compatibility
|
148
151
|
def reload_tools
|
149
|
-
warn "
|
152
|
+
warn "MiniMagick.reload_tools is deprecated because it is no longer necessary"
|
150
153
|
end
|
151
154
|
|
152
155
|
end
|
data/lib/mini_magick/image.rb
CHANGED
@@ -340,8 +340,7 @@ module MiniMagick
|
|
340
340
|
new_tempfile = MiniMagick::Utilities.tempfile(".#{format}")
|
341
341
|
new_path = new_tempfile.path
|
342
342
|
else
|
343
|
-
new_path = path.
|
344
|
-
new_path.sub!(/\[(\d+)\]/, '_\1') if layer?
|
343
|
+
new_path = Pathname(path).sub_ext(".#{format}").to_s
|
345
344
|
end
|
346
345
|
|
347
346
|
input_path = path.dup
|
@@ -354,7 +353,7 @@ module MiniMagick
|
|
354
353
|
end
|
355
354
|
|
356
355
|
if @tempfile
|
357
|
-
|
356
|
+
destroy!
|
358
357
|
@tempfile = new_tempfile
|
359
358
|
else
|
360
359
|
File.delete(path) unless path == new_path || layer?
|
@@ -467,7 +466,10 @@ module MiniMagick
|
|
467
466
|
# Destroys the tempfile (created by {.open}) if it exists.
|
468
467
|
#
|
469
468
|
def destroy!
|
470
|
-
|
469
|
+
if @tempfile
|
470
|
+
FileUtils.rm_f @tempfile.path.sub(/mpc$/, "cache") if @tempfile.path.end_with?(".mpc")
|
471
|
+
@tempfile.unlink
|
472
|
+
end
|
471
473
|
end
|
472
474
|
|
473
475
|
##
|
data/lib/mini_magick/shell.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "mini_magick/logger"
|
2
1
|
require "timeout"
|
2
|
+
require "benchmark"
|
3
3
|
|
4
4
|
module MiniMagick
|
5
5
|
##
|
@@ -11,25 +11,25 @@ module MiniMagick
|
|
11
11
|
class Shell
|
12
12
|
|
13
13
|
def run(command, options = {})
|
14
|
-
stdout, stderr,
|
14
|
+
stdout, stderr, status = execute(command, stdin: options[:stdin])
|
15
15
|
|
16
|
-
case
|
16
|
+
case status
|
17
17
|
when 1
|
18
18
|
fail MiniMagick::Error, "`#{command.join(" ")}` failed with error:\n#{stderr}"
|
19
19
|
when 127
|
20
20
|
fail MiniMagick::Error, stderr
|
21
|
-
end if options.fetch(:whiny,
|
21
|
+
end if options.fetch(:whiny, MiniMagick.whiny)
|
22
22
|
|
23
23
|
$stderr.print(stderr) unless options[:stderr] == false
|
24
24
|
|
25
|
-
stdout
|
25
|
+
[stdout, stderr, status]
|
26
26
|
end
|
27
27
|
|
28
|
-
def execute(command)
|
28
|
+
def execute(command, options = {})
|
29
29
|
stdout, stderr, status =
|
30
|
-
|
30
|
+
log(command.join(" ")) do
|
31
31
|
Timeout.timeout(MiniMagick.timeout) do
|
32
|
-
send("execute_#{MiniMagick.shell_api.gsub("-", "_")}",
|
32
|
+
send("execute_#{MiniMagick.shell_api.gsub("-", "_")}", command, options)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -38,18 +38,31 @@ module MiniMagick
|
|
38
38
|
["", "executable not found: \"#{command.first}\"", 127]
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
private
|
42
|
+
|
43
|
+
def execute_open3(command, options = {})
|
42
44
|
require "open3"
|
43
|
-
|
45
|
+
|
46
|
+
Open3.capture3(*command, binmode: true, stdin_data: options[:stdin].to_s)
|
44
47
|
end
|
45
48
|
|
46
|
-
def execute_posix_spawn(
|
49
|
+
def execute_posix_spawn(command, options = {})
|
47
50
|
require "posix-spawn"
|
51
|
+
|
48
52
|
pid, stdin, stdout, stderr = POSIX::Spawn.popen4(*command)
|
53
|
+
[stdin, stdout, stderr].each(&:binmode)
|
54
|
+
stdin.write(options[:stdin].to_s)
|
49
55
|
Process.waitpid(pid)
|
50
56
|
|
51
57
|
[stdout.read, stderr.read, $?]
|
52
58
|
end
|
53
59
|
|
60
|
+
def log(command, &block)
|
61
|
+
value = nil
|
62
|
+
duration = Benchmark.realtime { value = block.call }
|
63
|
+
MiniMagick.logger.debug "[%.2fs] %s" % [duration, command]
|
64
|
+
value
|
65
|
+
end
|
66
|
+
|
54
67
|
end
|
55
68
|
end
|
data/lib/mini_magick/tool.rb
CHANGED
@@ -49,13 +49,15 @@ module MiniMagick
|
|
49
49
|
# @param whiny [Boolean] Whether to raise errors on exit codes different
|
50
50
|
# than 0.
|
51
51
|
# @example
|
52
|
-
# MiniMagick::Tool::Identify.new(false) do |identify|
|
52
|
+
# MiniMagick::Tool::Identify.new(whiny: false) do |identify|
|
53
53
|
# identify.help # returns exit status 1, which would otherwise throw an error
|
54
54
|
# end
|
55
|
-
def initialize(name,
|
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
|
+
|
56
58
|
@name = name
|
57
|
-
@whiny = whiny
|
58
59
|
@args = []
|
60
|
+
@whiny = options.is_a?(Hash) ? options.fetch(:whiny, MiniMagick.whiny) : options
|
59
61
|
end
|
60
62
|
|
61
63
|
##
|
@@ -67,16 +69,30 @@ module MiniMagick
|
|
67
69
|
# mogrify << "path/to/image.jpg"
|
68
70
|
# mogrify.call # executes `mogrify -resize 500x500 path/to/image.jpg`
|
69
71
|
#
|
70
|
-
# @
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
72
|
+
# @example
|
73
|
+
# mogrify = MiniMagick::Tool::Mogrify.new
|
74
|
+
# # build the command
|
75
|
+
# mogrify.call do |stdout, stderr, status|
|
76
|
+
# # ...
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# @yield [Array] Optionally yields stdout, stderr, and exit status
|
74
80
|
#
|
75
|
-
# @return [String]
|
81
|
+
# @return [String] Returns the output of the command
|
76
82
|
#
|
77
|
-
def call(
|
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?
|
90
|
+
|
78
91
|
shell = MiniMagick::Shell.new
|
79
|
-
shell.run(command, options
|
92
|
+
stdout, stderr, status = shell.run(command, options)
|
93
|
+
yield stdout, stderr, status if block_given?
|
94
|
+
|
95
|
+
stdout.strip
|
80
96
|
end
|
81
97
|
|
82
98
|
##
|
@@ -171,6 +187,19 @@ module MiniMagick
|
|
171
187
|
self << ")"
|
172
188
|
end
|
173
189
|
|
190
|
+
##
|
191
|
+
# Adds ImageMagick's pseudo-filename `-` for standard input.
|
192
|
+
#
|
193
|
+
# @example
|
194
|
+
# identify = MiniMagick::Tool::Identify.new
|
195
|
+
# identify.stdin
|
196
|
+
# identify.call(stdin: image_content)
|
197
|
+
# # executes `identify -` with the given standard input
|
198
|
+
#
|
199
|
+
def stdin
|
200
|
+
self << "-"
|
201
|
+
end
|
202
|
+
|
174
203
|
##
|
175
204
|
# Define creator operator methods
|
176
205
|
#
|
@@ -216,9 +245,9 @@ module MiniMagick
|
|
216
245
|
|
217
246
|
def self.option_methods
|
218
247
|
@option_methods ||= (
|
219
|
-
tool = new
|
248
|
+
tool = new(whiny: false)
|
220
249
|
tool << "-help"
|
221
|
-
help_page = tool.call(
|
250
|
+
help_page = tool.call(stderr: false)
|
222
251
|
|
223
252
|
cli_options = help_page.scan(/^\s+-[a-z\-]+/).map(&:strip)
|
224
253
|
if tool.name == "mogrify" && MiniMagick.graphicsmagick?
|
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.5.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: 2016-
|
16
|
+
date: 2016-03-20 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rake
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- lib/mini_magick/configuration.rb
|
77
77
|
- lib/mini_magick/image.rb
|
78
78
|
- lib/mini_magick/image/info.rb
|
79
|
-
- lib/mini_magick/logger.rb
|
80
79
|
- lib/mini_magick/shell.rb
|
81
80
|
- lib/mini_magick/tool.rb
|
82
81
|
- lib/mini_magick/tool/animate.rb
|
@@ -113,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
112
|
requirements:
|
114
113
|
- You must have ImageMagick or GraphicsMagick installed
|
115
114
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.5.1
|
117
116
|
signing_key:
|
118
117
|
specification_version: 4
|
119
118
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
data/lib/mini_magick/logger.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require "benchmark"
|
2
|
-
|
3
|
-
module MiniMagick
|
4
|
-
##
|
5
|
-
# Responsible for logging commands to stdout (activated when
|
6
|
-
# `MiniMagick.debug` is set to `true`). Implements a simplified Logger
|
7
|
-
# interface.
|
8
|
-
#
|
9
|
-
# @private
|
10
|
-
#
|
11
|
-
class Logger
|
12
|
-
|
13
|
-
attr_accessor :format
|
14
|
-
|
15
|
-
def initialize(io)
|
16
|
-
@io = io
|
17
|
-
@format = "[%<duration>.2fs] %<command>s"
|
18
|
-
end
|
19
|
-
|
20
|
-
def debug(command, &action)
|
21
|
-
benchmark(action) do |duration|
|
22
|
-
output(duration: duration, command: command) if MiniMagick.debug
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def output(data)
|
27
|
-
printf @io, "#{format}\n", data
|
28
|
-
end
|
29
|
-
|
30
|
-
def benchmark(action)
|
31
|
-
return_value = nil
|
32
|
-
duration = Benchmark.realtime { return_value = action.call }
|
33
|
-
yield duration
|
34
|
-
return_value
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|