mini_magick 4.2.10 → 4.3.6

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
2
  SHA1:
3
- metadata.gz: 21c28d5cb2938a6c126985b362544f64858220aa
4
- data.tar.gz: 94bdee8c2c92bc7d9e5548202397dff054bd99bc
3
+ metadata.gz: 9d7353bb4abb1f24f782090a89632e2697cc8f77
4
+ data.tar.gz: ec2f0d8462829f39796474f292c4d06ef9f7ec35
5
5
  SHA512:
6
- metadata.gz: 907e11e72c97a02dcc8eaeb80d8c1bdee96561c8ae0134a14a2c00b4385e2dd6b1d9526dead4f523b4df219fe78c09fc1472609e87983a6d0b3d674aa21f8033
7
- data.tar.gz: d7f00b1e55cd0e5ab4abfaccd62fa220a34adbc03556a5b92626aa68dc41bd4c3dd61ac1fd0e7a4664a6e6e70971e95227350a11700dccb1ced09914edd782b7
6
+ metadata.gz: 9ceb0494e0c4d9f568482d2c7c8249ed91e01931ddfffd8e119df1de379e4f35343ba5c40af38daa4b021d359a3d44e4c3ab6e86e096d97487e9beb387697a55
7
+ data.tar.gz: 9bba8837c2ee3f10751932dee4afcd46724392d7e04a01ee1527aacb8c7043a092e7de7067f85e194da9e8cfeeff03a4d9ec11ea04c93151e8e020983bc0bd20
@@ -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,20 +129,11 @@ module MiniMagick
131
129
  def cli=(value)
132
130
  @cli = value
133
131
 
134
- case @cli
135
- when :imagemagick
136
- Utilities.which("mogrify") or
137
- raise MiniMagick::Error, "ImageMagick is not installed or CLI is not found"
138
- when :graphicsmagick
139
- Utilities.which("gm") or
140
- raise MiniMagick::Error, "GraphicsMagick is not installed or CLI is not found"
141
- else
132
+ if not [:imagemagick, :graphicsmagick].include?(@cli)
142
133
  raise ArgumentError,
143
134
  "CLI has to be set to either :imagemagick or :graphicsmagick" \
144
135
  ", was set to #{@cli.inspect}"
145
136
  end
146
-
147
- reload_tools
148
137
  end
149
138
 
150
139
  def cli_path
@@ -155,8 +144,9 @@ module MiniMagick
155
144
  @logger || MiniMagick::Logger.new($stdout)
156
145
  end
157
146
 
147
+ # Backwards compatibility
158
148
  def reload_tools
159
- MiniMagick::Tool::OptionMethods.instances.each(&:reload_methods)
149
+ warn "[MiniMagick] MiniMagick.reload_tools is deprecated because it is no longer necessary"
160
150
  end
161
151
 
162
152
  end
@@ -40,12 +40,15 @@ module MiniMagick
40
40
  @info.fetch(value) do
41
41
  format, width, height, size = self["%m %w %h %b"].split(" ")
42
42
 
43
+ path = @path
44
+ path = path.match(/\[\d+\]$/).pre_match if path =~ /\[\d+\]$/
45
+
43
46
  @info.update(
44
47
  "format" => format,
45
48
  "width" => Integer(width),
46
49
  "height" => Integer(height),
47
50
  "dimensions" => [Integer(width), Integer(height)],
48
- "size" => File.size(@path),
51
+ "size" => File.size(path),
49
52
  "human_size" => size,
50
53
  )
51
54
 
@@ -103,6 +106,7 @@ module MiniMagick
103
106
  details_string = identify(&:verbose)
104
107
  key_stack = []
105
108
  details_string.lines.to_a[1..-1].each_with_object({}) do |line, details_hash|
109
+ next if line.strip.length.zero?
106
110
  level = line[/^\s*/].length / 2 - 1
107
111
  key_stack.pop until key_stack.size <= level
108
112
 
@@ -119,9 +123,12 @@ module MiniMagick
119
123
  end
120
124
 
121
125
  def identify
126
+ path = @path
127
+ path += "[0]" unless path =~ /\[\d+\]$/
128
+
122
129
  MiniMagick::Tool::Identify.new do |builder|
123
130
  yield builder if block_given?
124
- builder << "#{@path}[0]"
131
+ builder << path
125
132
  end
126
133
  end
127
134
 
@@ -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? && MiniMagick::Tool::Mogrify.instance_methods.include?(name)
124
+ if args.any? && name != :resolution
125
125
  mogrify { |b| b.send(name, *args) }
126
126
  else
127
127
  @info[key, *args]
@@ -332,13 +332,11 @@ module MiniMagick
332
332
  # @return [self]
333
333
  #
334
334
  def format(format, page = 0)
335
- @info.clear
336
-
337
335
  if @tempfile
338
336
  new_tempfile = MiniMagick::Utilities.tempfile(".#{format}")
339
337
  new_path = new_tempfile.path
340
338
  else
341
- new_path = path.sub(/\.\w+$/, ".#{format}")
339
+ new_path = path.sub(/(\.\w+)?$/, ".#{format}")
342
340
  end
343
341
 
344
342
  MiniMagick::Tool::Convert.new do |convert|
@@ -355,6 +353,7 @@ module MiniMagick
355
353
  end
356
354
 
357
355
  path.replace new_path
356
+ @info.clear
358
357
 
359
358
  self
360
359
  end
@@ -387,16 +386,12 @@ module MiniMagick
387
386
  #
388
387
  def method_missing(name, *args)
389
388
  mogrify do |builder|
390
- if builder.respond_to?(name)
391
- builder.send(name, *args)
392
- else
393
- super
394
- end
389
+ builder.send(name, *args)
395
390
  end
396
391
  end
397
392
 
398
393
  def respond_to_missing?(method_name, include_private = false)
399
- MiniMagick::Tool::Mogrify.new.respond_to?(method_name, include_private)
394
+ MiniMagick::Tool::Mogrify.option_methods.include?(method_name.to_s)
400
395
  end
401
396
 
402
397
  ##
@@ -496,8 +491,6 @@ module MiniMagick
496
491
  end
497
492
 
498
493
  def mogrify(page = nil)
499
- @info.clear
500
-
501
494
  MiniMagick::Tool::Mogrify.new do |builder|
502
495
  builder.instance_eval do
503
496
  def format(*args)
@@ -509,6 +502,8 @@ module MiniMagick
509
502
  builder << (page ? "#{path}[#{page}]" : path)
510
503
  end
511
504
 
505
+ @info.clear
506
+
512
507
  self
513
508
  end
514
509
 
@@ -15,11 +15,10 @@ module MiniMagick
15
15
  #
16
16
  class Tool
17
17
 
18
- # @private
19
- def self.inherited(child)
20
- child_name = child.name.split("::").last.downcase
21
- child.send :include, MiniMagick::Tool::OptionMethods.new(child_name)
22
- end
18
+ CREATION_OPERATORS = %w[
19
+ xc canvas logo rose gradient radial-gradient plasma pattern label caption
20
+ text
21
+ ]
23
22
 
24
23
  ##
25
24
  # Aside from classic instantiation, it also accepts a block, and then
@@ -173,89 +172,52 @@ module MiniMagick
173
172
  end
174
173
 
175
174
  ##
176
- # Dynamically generates modules with dynamically generated option methods
177
- # for each command-line tool. It uses the `-help` page of a command-line
178
- # tool and generates methods from it. It then includes the generated
179
- # module into the tool class.
175
+ # Define creator operator methods
180
176
  #
181
- # @private
177
+ # mogrify = MiniMagick::Tool.new("mogrify")
178
+ # mogrify.canvas("khaki")
179
+ # mogrify.command.join(" ") #=> "mogrify canvas:khaki"
182
180
  #
183
- class OptionMethods < Module # think about it for a minute
184
-
185
- def self.instances
186
- @instances ||= []
187
- end
188
-
189
- def initialize(tool_name)
190
- @tool_name = tool_name
191
- reload_methods
192
- self.class.instances << self
193
- end
194
-
195
- def to_s
196
- "OptionMethods(#{@tool_name})"
197
- end
198
-
199
- ##
200
- # Dynamically generates operator methods from the "-help" page.
201
- #
202
- def reload_methods
203
- instance_methods(false).each { |method| undef_method(method) }
204
- creation_operator *creation_operators
205
- option *cli_options
206
- end
207
-
208
- ##
209
- # Creates method based on command-line option's name.
210
- #
211
- # mogrify = MiniMagick::Tool.new("mogrify")
212
- # mogrify.antialias
213
- # mogrify.depth(8)
214
- # mogrify.resize("500x500")
215
- # mogrify.command.join(" ")
216
- # #=> "mogrify -antialias -depth 8 -resize 500x500"
217
- #
218
- def option(*options)
219
- options.each do |option|
220
- define_method(option[1..-1].tr('-', '_')) do |*values|
221
- self << option
222
- self.merge!(values)
223
- self
224
- end
225
- end
181
+ CREATION_OPERATORS.each do |operator|
182
+ define_method(operator.gsub('-', '_')) do |value = nil|
183
+ self << "#{operator}:#{value}"
184
+ self
226
185
  end
186
+ end
227
187
 
228
- ##
229
- # Creates method based on creation operator's name.
230
- #
231
- # mogrify = MiniMagick::Tool.new("mogrify")
232
- # mogrify.canvas("khaki")
233
- # mogrify.command.join(" ") #=> "mogrify canvas:khaki"
234
- #
235
- def creation_operator(*operators)
236
- operators.each do |operator|
237
- define_method(operator.gsub('-', '_')) do |value = nil|
238
- self << "#{operator}:#{value}"
239
- self
240
- end
241
- end
242
- end
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
243
202
 
244
- def creation_operators
245
- %w[xc canvas logo rose gradient radial-gradient
246
- plasma tile pattern label caption text]
247
- end
203
+ def respond_to_missing?(method_name, include_private = false)
204
+ true
205
+ end
248
206
 
249
- def cli_options
250
- tool = MiniMagick::Tool.new(@tool_name)
207
+ def self.option_methods
208
+ @option_methods ||= (
209
+ tool = new
251
210
  tool << "-help"
252
211
  help_page = tool.call(false, stderr: false)
253
212
 
254
213
  cli_options = help_page.scan(/^\s+-[a-z\-]+/).map(&:strip)
255
- cli_options << "-gravity" if @tool_name == "mogrify" && MiniMagick.graphicsmagick?
256
- cli_options
257
- end
214
+ if tool.name == "mogrify" && MiniMagick.graphicsmagick?
215
+ # These options were undocumented before 2015-06-14 (see gm bug 302)
216
+ cli_options |= %w[-box -convolve -gravity -linewidth -mattecolor -render -shave]
217
+ end
258
218
 
219
+ cli_options.map { |o| o[1..-1].tr('-','_') }
220
+ )
259
221
  end
260
222
 
261
223
  end
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 2
12
- TINY = 10
11
+ MINOR = 3
12
+ TINY = 6
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
data/lib/mini_magick.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'mini_magick/version'
1
2
  require 'mini_magick/configuration'
2
3
 
3
4
  module MiniMagick
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.2.10
4
+ version: 4.3.6
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-08-08 00:00:00.000000000 Z
16
+ date: 2015-10-12 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake