mini_magick 4.3.6 → 4.5.1
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 +4 -4
- data/lib/mini_magick/configuration.rb +6 -3
- data/lib/mini_magick/image/info.rb +12 -2
- data/lib/mini_magick/image.rb +15 -5
- data/lib/mini_magick/shell.rb +24 -11
- data/lib/mini_magick/tool.rb +51 -12
- data/lib/mini_magick/version.rb +2 -2
- 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: b47a71b858d75780aca2cad04723b23ebbe03f43
|
4
|
+
data.tar.gz: 0435a6885e082c68913235ddad9219590e6d3400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41be6f64c5a0190da1b04e16c90bcd6c68133b165a8f8515d9231d17a8da3f6900965e7147643b8beae9515b2ab08cd23229f845e1b2dba69473374ceb7e68fc
|
7
|
+
data.tar.gz: 6eb28519339d44d5f658d4492708ebd459124c32bc0606a9fc9a2308de8eb442d0b11374bf9f486b7111f15ba05384dca346151ef410fb2bb082860a00d9ab7a
|
@@ -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).tap { |l| l.level = Logger::INFO }
|
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 = value ? Logger::DEBUG : Logger::INFO
|
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
|
@@ -106,9 +106,19 @@ module MiniMagick
|
|
106
106
|
details_string = identify(&:verbose)
|
107
107
|
key_stack = []
|
108
108
|
details_string.lines.to_a[1..-1].each_with_object({}) do |line, details_hash|
|
109
|
-
next if line.strip.length.zero?
|
109
|
+
next if !line.valid_encoding? || line.strip.length.zero?
|
110
|
+
|
110
111
|
level = line[/^\s*/].length / 2 - 1
|
111
|
-
|
112
|
+
if level >= 0
|
113
|
+
key_stack.pop until key_stack.size <= level
|
114
|
+
else
|
115
|
+
# Some metadata, such as SVG clipping paths, will be saved without
|
116
|
+
# indentation, resulting in a level of -1
|
117
|
+
last_key = details_hash.keys.last
|
118
|
+
details_hash[last_key] = '' if details_hash[last_key].empty?
|
119
|
+
details_hash[last_key] << line
|
120
|
+
next
|
121
|
+
end
|
112
122
|
|
113
123
|
key, _, value = line.partition(/:[\s\n]/).map(&:strip)
|
114
124
|
hash = key_stack.inject(details_hash) { |hash, key| hash.fetch(key) }
|
data/lib/mini_magick/image.rb
CHANGED
@@ -133,6 +133,10 @@ module MiniMagick
|
|
133
133
|
# @return [String] The location of the current working file
|
134
134
|
#
|
135
135
|
attr_reader :path
|
136
|
+
##
|
137
|
+
# @return [Tempfile] The underlying temporary file
|
138
|
+
#
|
139
|
+
attr_reader :tempfile
|
136
140
|
|
137
141
|
##
|
138
142
|
# Create a new {MiniMagick::Image} object.
|
@@ -336,20 +340,23 @@ module MiniMagick
|
|
336
340
|
new_tempfile = MiniMagick::Utilities.tempfile(".#{format}")
|
337
341
|
new_path = new_tempfile.path
|
338
342
|
else
|
339
|
-
new_path = path.
|
343
|
+
new_path = Pathname(path).sub_ext(".#{format}").to_s
|
340
344
|
end
|
341
345
|
|
346
|
+
input_path = path.dup
|
347
|
+
input_path << "[#{page}]" if page && !layer?
|
348
|
+
|
342
349
|
MiniMagick::Tool::Convert.new do |convert|
|
343
|
-
convert <<
|
350
|
+
convert << input_path
|
344
351
|
yield convert if block_given?
|
345
352
|
convert << new_path
|
346
353
|
end
|
347
354
|
|
348
355
|
if @tempfile
|
349
|
-
|
356
|
+
destroy!
|
350
357
|
@tempfile = new_tempfile
|
351
358
|
else
|
352
|
-
File.delete(path) unless path == new_path
|
359
|
+
File.delete(path) unless path == new_path || layer?
|
353
360
|
end
|
354
361
|
|
355
362
|
path.replace new_path
|
@@ -459,7 +466,10 @@ module MiniMagick
|
|
459
466
|
# Destroys the tempfile (created by {.open}) if it exists.
|
460
467
|
#
|
461
468
|
def destroy!
|
462
|
-
|
469
|
+
if @tempfile
|
470
|
+
FileUtils.rm_f @tempfile.path.sub(/mpc$/, "cache") if @tempfile.path.end_with?(".mpc")
|
471
|
+
@tempfile.unlink
|
472
|
+
end
|
463
473
|
end
|
464
474
|
|
465
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
|
#
|
@@ -185,6 +214,16 @@ module MiniMagick
|
|
185
214
|
end
|
186
215
|
end
|
187
216
|
|
217
|
+
##
|
218
|
+
# This option is a valid ImageMagick option, but it's also a Ruby method,
|
219
|
+
# so we need to override it so that it correctly acts as an option method.
|
220
|
+
#
|
221
|
+
def clone(*args)
|
222
|
+
self << '-clone'
|
223
|
+
self.merge!(args)
|
224
|
+
self
|
225
|
+
end
|
226
|
+
|
188
227
|
##
|
189
228
|
# Any undefined method will be transformed into a CLI option
|
190
229
|
#
|
@@ -206,9 +245,9 @@ module MiniMagick
|
|
206
245
|
|
207
246
|
def self.option_methods
|
208
247
|
@option_methods ||= (
|
209
|
-
tool = new
|
248
|
+
tool = new(whiny: false)
|
210
249
|
tool << "-help"
|
211
|
-
help_page = tool.call(
|
250
|
+
help_page = tool.call(stderr: false)
|
212
251
|
|
213
252
|
cli_options = help_page.scan(/^\s+-[a-z\-]+/).map(&:strip)
|
214
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.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:
|
16
|
+
date: 2016-03-25 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
|