mini_magick 4.2.4 → 4.3.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.
- checksums.yaml +4 -4
- data/lib/mini_magick/configuration.rb +4 -7
- data/lib/mini_magick/image/info.rb +7 -7
- data/lib/mini_magick/image.rb +10 -8
- data/lib/mini_magick/shell.rb +3 -7
- data/lib/mini_magick/tool.rb +45 -94
- data/lib/mini_magick/version.rb +2 -2
- data/lib/mini_magick.rb +4 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea018518f84a24383054e66dfd339b36d004f3f0
|
|
4
|
+
data.tar.gz: 90b0ab0e59ce32941f9d804915ce29ddbbaa247f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12c91ebcb9b87f12a9ee2b55e3857d8b75ef840a5c941ea36cb284c949f026f819b2aeabdcf4172f22a9f656a7db9536ac5223bb7caaa0ce120d100bf0120c0d
|
|
7
|
+
data.tar.gz: 537dd43b9e236ad805faa32a12d6d30a94c36f761719002c73a145fcf5ca35f8b5028c3e42182e396a6bab8ada521439297a34327cf07e8b2063355926fcd7d0
|
|
@@ -7,7 +7,7 @@ module MiniMagick
|
|
|
7
7
|
# Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
|
|
8
8
|
# [GraphicsMagick](http://www.graphicsmagick.org).
|
|
9
9
|
#
|
|
10
|
-
# @return [Symbol] `:imagemagick` or `:
|
|
10
|
+
# @return [Symbol] `:imagemagick` or `:graphicsmagick`
|
|
11
11
|
#
|
|
12
12
|
attr_accessor :cli
|
|
13
13
|
# @private (for backwards compatibility)
|
|
@@ -114,8 +114,6 @@ module MiniMagick
|
|
|
114
114
|
"processor has to be set to either \"mogrify\" or \"gm\"" \
|
|
115
115
|
", was set to #{@processor.inspect}"
|
|
116
116
|
end
|
|
117
|
-
|
|
118
|
-
reload_tools
|
|
119
117
|
end
|
|
120
118
|
|
|
121
119
|
def cli
|
|
@@ -131,13 +129,11 @@ module MiniMagick
|
|
|
131
129
|
def cli=(value)
|
|
132
130
|
@cli = value
|
|
133
131
|
|
|
134
|
-
|
|
132
|
+
if not [:imagemagick, :graphicsmagick].include?(@cli)
|
|
135
133
|
raise ArgumentError,
|
|
136
134
|
"CLI has to be set to either :imagemagick or :graphicsmagick" \
|
|
137
135
|
", was set to #{@cli.inspect}"
|
|
138
136
|
end
|
|
139
|
-
|
|
140
|
-
reload_tools
|
|
141
137
|
end
|
|
142
138
|
|
|
143
139
|
def cli_path
|
|
@@ -148,8 +144,9 @@ module MiniMagick
|
|
|
148
144
|
@logger || MiniMagick::Logger.new($stdout)
|
|
149
145
|
end
|
|
150
146
|
|
|
147
|
+
# Backwards compatibility
|
|
151
148
|
def reload_tools
|
|
152
|
-
MiniMagick
|
|
149
|
+
warn "[MiniMagick] MiniMagick.reload_tools is deprecated because it is no longer necessary"
|
|
153
150
|
end
|
|
154
151
|
|
|
155
152
|
end
|
|
@@ -11,7 +11,7 @@ module MiniMagick
|
|
|
11
11
|
|
|
12
12
|
def [](value, *args)
|
|
13
13
|
case value
|
|
14
|
-
when "format", "width", "height", "dimensions", "size"
|
|
14
|
+
when "format", "width", "height", "dimensions", "size", "human_size"
|
|
15
15
|
cheap_info(value)
|
|
16
16
|
when "colorspace"
|
|
17
17
|
colorspace
|
|
@@ -45,7 +45,8 @@ module MiniMagick
|
|
|
45
45
|
"width" => Integer(width),
|
|
46
46
|
"height" => Integer(height),
|
|
47
47
|
"dimensions" => [Integer(width), Integer(height)],
|
|
48
|
-
"size" => size
|
|
48
|
+
"size" => File.size(@path),
|
|
49
|
+
"human_size" => size,
|
|
49
50
|
)
|
|
50
51
|
|
|
51
52
|
@info.fetch(value)
|
|
@@ -100,10 +101,11 @@ module MiniMagick
|
|
|
100
101
|
def details
|
|
101
102
|
@info["details"] ||= (
|
|
102
103
|
details_string = identify(&:verbose)
|
|
103
|
-
|
|
104
|
+
key_stack = []
|
|
105
|
+
details_string.lines.to_a[1..-1].each_with_object({}) do |line, details_hash|
|
|
106
|
+
next if line.strip.length.zero?
|
|
104
107
|
level = line[/^\s*/].length / 2 - 1
|
|
105
|
-
|
|
106
|
-
key_stack.pop if level < key_stack.size
|
|
108
|
+
key_stack.pop until key_stack.size <= level
|
|
107
109
|
|
|
108
110
|
key, _, value = line.partition(/:[\s\n]/).map(&:strip)
|
|
109
111
|
hash = key_stack.inject(details_hash) { |hash, key| hash.fetch(key) }
|
|
@@ -113,8 +115,6 @@ module MiniMagick
|
|
|
113
115
|
else
|
|
114
116
|
hash[key] = value
|
|
115
117
|
end
|
|
116
|
-
|
|
117
|
-
details_hash
|
|
118
118
|
end
|
|
119
119
|
)
|
|
120
120
|
end
|
data/lib/mini_magick/image.rb
CHANGED
|
@@ -121,7 +121,7 @@ module MiniMagick
|
|
|
121
121
|
#
|
|
122
122
|
def self.attribute(name, key = name.to_s)
|
|
123
123
|
define_method(name) do |*args|
|
|
124
|
-
if args.any? &&
|
|
124
|
+
if args.any? && name != :resolution
|
|
125
125
|
mogrify { |b| b.send(name, *args) }
|
|
126
126
|
else
|
|
127
127
|
@info[key, *args]
|
|
@@ -223,12 +223,18 @@ module MiniMagick
|
|
|
223
223
|
#
|
|
224
224
|
attribute :dimensions
|
|
225
225
|
##
|
|
226
|
-
# Returns the file size of the image.
|
|
226
|
+
# Returns the file size of the image (in bytes).
|
|
227
227
|
#
|
|
228
228
|
# @return [Integer]
|
|
229
229
|
#
|
|
230
230
|
attribute :size
|
|
231
231
|
##
|
|
232
|
+
# Returns the file size in a human readable format.
|
|
233
|
+
#
|
|
234
|
+
# @return [String]
|
|
235
|
+
#
|
|
236
|
+
attribute :human_size
|
|
237
|
+
##
|
|
232
238
|
# @return [String]
|
|
233
239
|
#
|
|
234
240
|
attribute :colorspace
|
|
@@ -381,16 +387,12 @@ module MiniMagick
|
|
|
381
387
|
#
|
|
382
388
|
def method_missing(name, *args)
|
|
383
389
|
mogrify do |builder|
|
|
384
|
-
|
|
385
|
-
builder.send(name, *args)
|
|
386
|
-
else
|
|
387
|
-
super
|
|
388
|
-
end
|
|
390
|
+
builder.send(name, *args)
|
|
389
391
|
end
|
|
390
392
|
end
|
|
391
393
|
|
|
392
394
|
def respond_to_missing?(method_name, include_private = false)
|
|
393
|
-
|
|
395
|
+
true
|
|
394
396
|
end
|
|
395
397
|
|
|
396
398
|
##
|
data/lib/mini_magick/shell.rb
CHANGED
|
@@ -10,11 +10,7 @@ module MiniMagick
|
|
|
10
10
|
#
|
|
11
11
|
class Shell
|
|
12
12
|
|
|
13
|
-
def
|
|
14
|
-
@whiny = whiny
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def run(command)
|
|
13
|
+
def run(command, options = {})
|
|
18
14
|
stdout, stderr, code = execute(command)
|
|
19
15
|
|
|
20
16
|
case code
|
|
@@ -22,9 +18,9 @@ module MiniMagick
|
|
|
22
18
|
fail MiniMagick::Error, "`#{command.join(" ")}` failed with error:\n#{stderr}"
|
|
23
19
|
when 127
|
|
24
20
|
fail MiniMagick::Error, stderr
|
|
25
|
-
end if
|
|
21
|
+
end if options.fetch(:whiny, true)
|
|
26
22
|
|
|
27
|
-
$stderr.print(stderr)
|
|
23
|
+
$stderr.print(stderr) unless options[:stderr] == false
|
|
28
24
|
|
|
29
25
|
stdout
|
|
30
26
|
end
|
data/lib/mini_magick/tool.rb
CHANGED
|
@@ -15,23 +15,10 @@ module MiniMagick
|
|
|
15
15
|
#
|
|
16
16
|
class Tool
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
autoload :Convert, "mini_magick/tool/convert"
|
|
23
|
-
autoload :Display, "mini_magick/tool/display"
|
|
24
|
-
autoload :Identify, "mini_magick/tool/identify"
|
|
25
|
-
autoload :Import, "mini_magick/tool/import"
|
|
26
|
-
autoload :Mogrify, "mini_magick/tool/mogrify"
|
|
27
|
-
autoload :Montage, "mini_magick/tool/montage"
|
|
28
|
-
autoload :Stream, "mini_magick/tool/stream"
|
|
29
|
-
|
|
30
|
-
# @private
|
|
31
|
-
def self.inherited(child)
|
|
32
|
-
child_name = child.name.split("::").last.downcase
|
|
33
|
-
child.send :include, MiniMagick::Tool::OptionMethods.new(child_name)
|
|
34
|
-
end
|
|
18
|
+
CREATION_OPERATORS = %w[
|
|
19
|
+
xc canvas logo rose gradient radial-gradient plasma tile pattern label
|
|
20
|
+
caption text
|
|
21
|
+
]
|
|
35
22
|
|
|
36
23
|
##
|
|
37
24
|
# Aside from classic instantiation, it also accepts a block, and then
|
|
@@ -78,7 +65,7 @@ module MiniMagick
|
|
|
78
65
|
# mogrify = MiniMagick::Tool::Mogrify.new
|
|
79
66
|
# mogrify.resize("500x500")
|
|
80
67
|
# mogrify << "path/to/image.jpg"
|
|
81
|
-
#
|
|
68
|
+
# mogrify.call # executes `mogrify -resize 500x500 path/to/image.jpg`
|
|
82
69
|
#
|
|
83
70
|
# @param whiny [Boolean] Whether you want an error to be raised when
|
|
84
71
|
# ImageMagick returns an exit code of 1. You may want this because
|
|
@@ -87,9 +74,9 @@ module MiniMagick
|
|
|
87
74
|
#
|
|
88
75
|
# @return [String] Output of the command
|
|
89
76
|
#
|
|
90
|
-
def call(whiny = @whiny)
|
|
91
|
-
shell = MiniMagick::Shell.new
|
|
92
|
-
shell.run(command).strip
|
|
77
|
+
def call(whiny = @whiny, options = {})
|
|
78
|
+
shell = MiniMagick::Shell.new
|
|
79
|
+
shell.run(command, options.merge(whiny: whiny)).strip
|
|
93
80
|
end
|
|
94
81
|
|
|
95
82
|
##
|
|
@@ -185,85 +172,49 @@ module MiniMagick
|
|
|
185
172
|
end
|
|
186
173
|
|
|
187
174
|
##
|
|
188
|
-
#
|
|
189
|
-
# for each command-line tool. It uses the `-help` page of a command-line
|
|
190
|
-
# tool and generates methods from it. It then includes the generated
|
|
191
|
-
# module into the tool class.
|
|
175
|
+
# Define creator operator methods
|
|
192
176
|
#
|
|
193
|
-
#
|
|
177
|
+
# mogrify = MiniMagick::Tool.new("mogrify")
|
|
178
|
+
# mogrify.canvas("khaki")
|
|
179
|
+
# mogrify.command.join(" ") #=> "mogrify canvas:khaki"
|
|
194
180
|
#
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def initialize(tool_name)
|
|
202
|
-
@tool_name = tool_name
|
|
203
|
-
reload_methods
|
|
204
|
-
self.class.instances << self
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def to_s
|
|
208
|
-
"OptionMethods(#{@tool_name})"
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
##
|
|
212
|
-
# Dynamically generates operator methods from the "-help" page.
|
|
213
|
-
#
|
|
214
|
-
def reload_methods
|
|
215
|
-
instance_methods(false).each { |method| undef_method(method) }
|
|
216
|
-
creation_operator *creation_operators
|
|
217
|
-
option *cli_options
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
##
|
|
221
|
-
# Creates method based on command-line option's name.
|
|
222
|
-
#
|
|
223
|
-
# mogrify = MiniMagick::Tool.new("mogrify")
|
|
224
|
-
# mogrify.antialias
|
|
225
|
-
# mogrify.depth(8)
|
|
226
|
-
# mogrify.resize("500x500")
|
|
227
|
-
# mogirfy.command.join(" ")
|
|
228
|
-
# #=> "mogrify -antialias -depth 8 -resize 500x500"
|
|
229
|
-
#
|
|
230
|
-
def option(*options)
|
|
231
|
-
options.each do |option|
|
|
232
|
-
define_method(option[1..-1].gsub('-', '_')) do |*values|
|
|
233
|
-
self << option
|
|
234
|
-
self.merge!(values)
|
|
235
|
-
self
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
##
|
|
241
|
-
# Creates method based on creation operator's name.
|
|
242
|
-
#
|
|
243
|
-
# mogrify = MiniMagick::Tool.new("mogrify")
|
|
244
|
-
# mogrify.canvas("khaki")
|
|
245
|
-
# mogrify.command.join(" ") #=> "mogrify canvas:khaki"
|
|
246
|
-
#
|
|
247
|
-
def creation_operator(*operators)
|
|
248
|
-
operators.each do |operator|
|
|
249
|
-
define_method(operator.gsub('-', '_')) do |value = nil|
|
|
250
|
-
self << "#{operator}:#{value}"
|
|
251
|
-
self
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
def creation_operators
|
|
257
|
-
%w[xc canvas logo rose gradient radial-gradient
|
|
258
|
-
plasma tile pattern label caption text]
|
|
181
|
+
CREATION_OPERATORS.each do |operator|
|
|
182
|
+
define_method(operator.gsub('-', '_')) do |value = nil|
|
|
183
|
+
self << "#{operator}:#{value}"
|
|
184
|
+
self
|
|
259
185
|
end
|
|
186
|
+
end
|
|
260
187
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
188
|
+
##
|
|
189
|
+
# Any undefined method will be transformed into a CLI option
|
|
190
|
+
#
|
|
191
|
+
# mogrify = MiniMagick::Tool.new("mogrify")
|
|
192
|
+
# mogrify.adaptive_blur("...")
|
|
193
|
+
# mogrify.foo_bar
|
|
194
|
+
# mogrify.command.join(" ") "mogrify -adaptive-blur ... -foo-bar"
|
|
195
|
+
#
|
|
196
|
+
def method_missing(name, *args)
|
|
197
|
+
option = "-#{name.to_s.tr('_', '-')}"
|
|
198
|
+
self << option
|
|
199
|
+
self.merge!(args)
|
|
200
|
+
self
|
|
201
|
+
end
|
|
265
202
|
|
|
203
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
204
|
+
true
|
|
266
205
|
end
|
|
267
206
|
|
|
268
207
|
end
|
|
269
208
|
end
|
|
209
|
+
|
|
210
|
+
require "mini_magick/tool/animate"
|
|
211
|
+
require "mini_magick/tool/compare"
|
|
212
|
+
require "mini_magick/tool/composite"
|
|
213
|
+
require "mini_magick/tool/conjure"
|
|
214
|
+
require "mini_magick/tool/convert"
|
|
215
|
+
require "mini_magick/tool/display"
|
|
216
|
+
require "mini_magick/tool/identify"
|
|
217
|
+
require "mini_magick/tool/import"
|
|
218
|
+
require "mini_magick/tool/mogrify"
|
|
219
|
+
require "mini_magick/tool/montage"
|
|
220
|
+
require "mini_magick/tool/stream"
|
data/lib/mini_magick/version.rb
CHANGED
data/lib/mini_magick.rb
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
require 'mini_magick/configuration'
|
|
2
|
-
require 'mini_magick/tool'
|
|
3
|
-
require 'mini_magick/image'
|
|
4
2
|
|
|
5
3
|
module MiniMagick
|
|
6
4
|
|
|
@@ -19,6 +17,7 @@ module MiniMagick
|
|
|
19
17
|
old_cli = self.cli
|
|
20
18
|
self.cli = cli
|
|
21
19
|
yield
|
|
20
|
+
ensure
|
|
22
21
|
self.cli = old_cli
|
|
23
22
|
end
|
|
24
23
|
|
|
@@ -51,3 +50,6 @@ module MiniMagick
|
|
|
51
50
|
class Invalid < StandardError; end
|
|
52
51
|
|
|
53
52
|
end
|
|
53
|
+
|
|
54
|
+
require 'mini_magick/tool'
|
|
55
|
+
require 'mini_magick/image'
|
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.3.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: 2015-
|
|
16
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
|
17
17
|
dependencies:
|
|
18
18
|
- !ruby/object:Gem::Dependency
|
|
19
19
|
name: rake
|
|
@@ -118,3 +118,4 @@ signing_key:
|
|
|
118
118
|
specification_version: 4
|
|
119
119
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
|
120
120
|
test_files: []
|
|
121
|
+
has_rdoc:
|