mini_magick 4.2.7 → 4.3.3

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: 2ebe50720f44094421fa8d0f27a3a6934f69f70b
4
- data.tar.gz: 24d09b9541aa1c4bf258000147e1be96b9f3bdf3
3
+ metadata.gz: 8d1f35dada1d7067b098917d946c23447a4c5887
4
+ data.tar.gz: 322b79ddc7af71be2a0df17772b094ae7cd88d7e
5
5
  SHA512:
6
- metadata.gz: 42a75ad425fb787c4a7e74a25eaee6cb687df34e765e2e62a365f70a0f05d31763f486abc0274b127fac3a41b76c3bc9c031f477603ad482c0e309e2844f2b08
7
- data.tar.gz: dcba1f309e1a09759c6ffb6cc0aaf154d789d4c5ef9a9282d19a297e64844838af46654dd23648317721ea360170c8de90017ad6444b6082e8d15d7913f9b3fb
6
+ metadata.gz: 66e6b584ddf9b0b14e5be67a4aba8943a38f1ffa33e5708c5dde5c0e244e9a2c7f09b8ec92a33ea6ce46c2a3ecc916d4c39a0da5440ca9d1fa6b3dabd6e743f1
7
+ data.tar.gz: 7b95930540ee115e8e894644efc848c48692077f77f81fa203d3d85d922452df5a38ca81e2b769825dc24b0d60d7bf2f2a94c4b09788d0825f6986d71021f77e
@@ -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 `:minimagick`
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
- unless [:imagemagick, :graphicsmagick].include?(@cli)
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::Tool::OptionMethods.instances.each(&:reload_methods)
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.to_i,
48
+ "size" => File.size(@path),
49
+ "human_size" => size,
49
50
  )
50
51
 
51
52
  @info.fetch(value)
@@ -102,6 +103,7 @@ module MiniMagick
102
103
  details_string = identify(&:verbose)
103
104
  key_stack = []
104
105
  details_string.lines.to_a[1..-1].each_with_object({}) do |line, details_hash|
106
+ next if line.strip.length.zero?
105
107
  level = line[/^\s*/].length / 2 - 1
106
108
  key_stack.pop until key_stack.size <= level
107
109
 
@@ -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]
@@ -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
@@ -326,13 +332,11 @@ module MiniMagick
326
332
  # @return [self]
327
333
  #
328
334
  def format(format, page = 0)
329
- @info.clear
330
-
331
335
  if @tempfile
332
336
  new_tempfile = MiniMagick::Utilities.tempfile(".#{format}")
333
337
  new_path = new_tempfile.path
334
338
  else
335
- new_path = path.sub(/\.\w+$/, ".#{format}")
339
+ new_path = path.sub(/(\.\w+)?$/, ".#{format}")
336
340
  end
337
341
 
338
342
  MiniMagick::Tool::Convert.new do |convert|
@@ -349,6 +353,7 @@ module MiniMagick
349
353
  end
350
354
 
351
355
  path.replace new_path
356
+ @info.clear
352
357
 
353
358
  self
354
359
  end
@@ -381,16 +386,12 @@ module MiniMagick
381
386
  #
382
387
  def method_missing(name, *args)
383
388
  mogrify do |builder|
384
- if builder.respond_to?(name)
385
- builder.send(name, *args)
386
- else
387
- super
388
- end
389
+ builder.send(name, *args)
389
390
  end
390
391
  end
391
392
 
392
393
  def respond_to_missing?(method_name, include_private = false)
393
- MiniMagick::Tool::Mogrify.new.respond_to?(method_name, include_private)
394
+ true
394
395
  end
395
396
 
396
397
  ##
@@ -490,8 +491,6 @@ module MiniMagick
490
491
  end
491
492
 
492
493
  def mogrify(page = nil)
493
- @info.clear
494
-
495
494
  MiniMagick::Tool::Mogrify.new do |builder|
496
495
  builder.instance_eval do
497
496
  def format(*args)
@@ -503,6 +502,8 @@ module MiniMagick
503
502
  builder << (page ? "#{path}[#{page}]" : path)
504
503
  end
505
504
 
505
+ @info.clear
506
+
506
507
  self
507
508
  end
508
509
 
@@ -10,11 +10,7 @@ module MiniMagick
10
10
  #
11
11
  class Shell
12
12
 
13
- def initialize(whiny = true)
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 @whiny
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
@@ -15,23 +15,10 @@ module MiniMagick
15
15
  #
16
16
  class Tool
17
17
 
18
- autoload :Animate, "mini_magick/tool/animate"
19
- autoload :Compare, "mini_magick/tool/compare"
20
- autoload :Composite, "mini_magick/tool/composite"
21
- autoload :Conjure, "mini_magick/tool/conjure"
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
- # mogirfy.call # executes `mogrify -resize 500x500 path/to/image.jpg`
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(whiny)
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
- # Dynamically generates modules with dynamically generated option methods
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
- # @private
177
+ # mogrify = MiniMagick::Tool.new("mogrify")
178
+ # mogrify.canvas("khaki")
179
+ # mogrify.command.join(" ") #=> "mogrify canvas:khaki"
194
180
  #
195
- class OptionMethods < Module # think about it for a minute
196
-
197
- def self.instances
198
- @instances ||= []
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].tr('-', '_')) 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
- def cli_options
262
- help = MiniMagick::Tool.new(@tool_name, false) { |b| b << "-help" }
263
- cli_options = help.scan(/^\s+-[a-z\-]+/).map(&:strip)
264
- 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
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"
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 2
12
- TINY = 7
11
+ MINOR = 3
12
+ TINY = 3
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
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.2.7
4
+ version: 4.3.3
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-05-28 00:00:00.000000000 Z
16
+ date: 2015-09-09 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: