mini_magick 4.2.9 → 4.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40fe759f030711a8b4cae6a7334ba2c553f848a3
4
- data.tar.gz: 37037fc7631d55294c20ad991dbc8f0bfb6c8fb2
3
+ metadata.gz: 7f0d6f6689137d1749757919b43718103e708beb
4
+ data.tar.gz: 310371ca24dc3ab384f2eaff5dcfc2053cdf0d99
5
5
  SHA512:
6
- metadata.gz: 89c0deeaf8dc29605ac7651803be5af576822fcfa8485056254eec3710d31563a9f7d536b2f35d7e677d0b8ab9a4a35d5147aec18d0fba8e1fb9fbcb97f454b2
7
- data.tar.gz: c553cc750c068c345fbc2757af7eb063e4d222102313f2a64930f9d67ff16adadfc636fe6b17b6377ce03bea0335f0f77d9a47ee6b7652ec02eb3cbf9b5eff28
6
+ metadata.gz: bbaa819729b8f53bd43cfbc3f3d82bba32ca50d6f76730176ec99239ecf519752962f1040b11b5fbca17d4d092f9ddd362aa0e87aab62410043cc2375c6e2bc2
7
+ data.tar.gz: 1a3163bcc33173731cd6c0d22e3b0cf2a54c3516426dc72bf2eb67826f5efc431af8b8ea1af6435539d4a035b70466728448e1d00d63685a785d79d3870d40e2
@@ -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,8 +106,19 @@ 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.valid_encoding? || line.strip.length.zero?
110
+
106
111
  level = line[/^\s*/].length / 2 - 1
107
- key_stack.pop until key_stack.size <= level
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
108
122
 
109
123
  key, _, value = line.partition(/:[\s\n]/).map(&:strip)
110
124
  hash = key_stack.inject(details_hash) { |hash, key| hash.fetch(key) }
@@ -119,9 +133,12 @@ module MiniMagick
119
133
  end
120
134
 
121
135
  def identify
136
+ path = @path
137
+ path += "[0]" unless path =~ /\[\d+\]$/
138
+
122
139
  MiniMagick::Tool::Identify.new do |builder|
123
140
  yield builder if block_given?
124
- builder << "#{@path}[0]"
141
+ builder << path
125
142
  end
126
143
  end
127
144
 
@@ -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]
@@ -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.
@@ -332,17 +336,19 @@ module MiniMagick
332
336
  # @return [self]
333
337
  #
334
338
  def format(format, page = 0)
335
- @info.clear
336
-
337
339
  if @tempfile
338
340
  new_tempfile = MiniMagick::Utilities.tempfile(".#{format}")
339
341
  new_path = new_tempfile.path
340
342
  else
341
- new_path = path.sub(/\.\w+$/, ".#{format}")
343
+ new_path = path.sub(/(\.\w+)?$/, ".#{format}")
344
+ new_path.sub!(/\[(\d+)\]/, '_\1') if layer?
342
345
  end
343
346
 
347
+ input_path = path.dup
348
+ input_path << "[#{page}]" if page && !layer?
349
+
344
350
  MiniMagick::Tool::Convert.new do |convert|
345
- convert << (page ? "#{path}[#{page}]" : path)
351
+ convert << input_path
346
352
  yield convert if block_given?
347
353
  convert << new_path
348
354
  end
@@ -351,10 +357,11 @@ module MiniMagick
351
357
  @tempfile.unlink
352
358
  @tempfile = new_tempfile
353
359
  else
354
- File.delete(path) unless path == new_path
360
+ File.delete(path) unless path == new_path || layer?
355
361
  end
356
362
 
357
363
  path.replace new_path
364
+ @info.clear
358
365
 
359
366
  self
360
367
  end
@@ -387,16 +394,12 @@ module MiniMagick
387
394
  #
388
395
  def method_missing(name, *args)
389
396
  mogrify do |builder|
390
- if builder.respond_to?(name)
391
- builder.send(name, *args)
392
- else
393
- super
394
- end
397
+ builder.send(name, *args)
395
398
  end
396
399
  end
397
400
 
398
401
  def respond_to_missing?(method_name, include_private = false)
399
- MiniMagick::Tool::Mogrify.new.respond_to?(method_name, include_private)
402
+ MiniMagick::Tool::Mogrify.option_methods.include?(method_name.to_s)
400
403
  end
401
404
 
402
405
  ##
@@ -496,8 +499,6 @@ module MiniMagick
496
499
  end
497
500
 
498
501
  def mogrify(page = nil)
499
- @info.clear
500
-
501
502
  MiniMagick::Tool::Mogrify.new do |builder|
502
503
  builder.instance_eval do
503
504
  def format(*args)
@@ -509,6 +510,8 @@ module MiniMagick
509
510
  builder << (page ? "#{path}[#{page}]" : path)
510
511
  end
511
512
 
513
+ @info.clear
514
+
512
515
  self
513
516
  end
514
517
 
@@ -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,86 +172,62 @@ 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 ||= []
181
+ CREATION_OPERATORS.each do |operator|
182
+ define_method(operator.gsub('-', '_')) do |value = nil|
183
+ self << "#{operator}:#{value}"
184
+ self
187
185
  end
186
+ end
188
187
 
189
- def initialize(tool_name)
190
- @tool_name = tool_name
191
- reload_methods
192
- self.class.instances << self
193
- end
188
+ ##
189
+ # This option is a valid ImageMagick option, but it's also a Ruby method,
190
+ # so we need to override it so that it correctly acts as an option method.
191
+ #
192
+ def clone(*args)
193
+ self << '-clone'
194
+ self.merge!(args)
195
+ self
196
+ end
194
197
 
195
- def to_s
196
- "OptionMethods(#{@tool_name})"
197
- end
198
+ ##
199
+ # Any undefined method will be transformed into a CLI option
200
+ #
201
+ # mogrify = MiniMagick::Tool.new("mogrify")
202
+ # mogrify.adaptive_blur("...")
203
+ # mogrify.foo_bar
204
+ # mogrify.command.join(" ") "mogrify -adaptive-blur ... -foo-bar"
205
+ #
206
+ def method_missing(name, *args)
207
+ option = "-#{name.to_s.tr('_', '-')}"
208
+ self << option
209
+ self.merge!(args)
210
+ self
211
+ end
198
212
 
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
213
+ def respond_to_missing?(method_name, include_private = false)
214
+ true
215
+ end
207
216
 
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
226
- end
217
+ def self.option_methods
218
+ @option_methods ||= (
219
+ tool = new
220
+ tool << "-help"
221
+ help_page = tool.call(false, stderr: false)
227
222
 
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
223
+ cli_options = help_page.scan(/^\s+-[a-z\-]+/).map(&:strip)
224
+ if tool.name == "mogrify" && MiniMagick.graphicsmagick?
225
+ # These options were undocumented before 2015-06-14 (see gm bug 302)
226
+ cli_options |= %w[-box -convolve -gravity -linewidth -mattecolor -render -shave]
241
227
  end
242
- end
243
-
244
- def creation_operators
245
- %w[xc canvas logo rose gradient radial-gradient
246
- plasma tile pattern label caption text]
247
- end
248
-
249
- def cli_options
250
- tool = MiniMagick::Tool.new(@tool_name)
251
- tool << "-help"
252
- help = tool.call(false, stderr: false)
253
- cli_options = help.scan(/^\s+-[a-z\-]+/).map(&:strip)
254
- end
255
228
 
229
+ cli_options.map { |o| o[1..-1].tr('-','_') }
230
+ )
256
231
  end
257
232
 
258
233
  end
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 2
12
- TINY = 9
11
+ MINOR = 4
12
+ TINY = 0
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.9
4
+ version: 4.4.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: 2015-08-02 00:00:00.000000000 Z
16
+ date: 2016-02-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake