mini_magick 4.2.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d12d070a6cade08e59789a2eea4aa5a34b7974e
4
- data.tar.gz: f0fdaaa0272473a90c2dc69a3d4bbd856e252c43
3
+ metadata.gz: ea018518f84a24383054e66dfd339b36d004f3f0
4
+ data.tar.gz: 90b0ab0e59ce32941f9d804915ce29ddbbaa247f
5
5
  SHA512:
6
- metadata.gz: e9fa5b044807be690f968325ed52a755e1cd8fd3361242b9f36cb3e89945dafeb513e6ebcd4ce509f5ecdf914ba48d73233286581d7268a2f093529611f8865a
7
- data.tar.gz: 79220b3f2fe46676b1c6ab8411bac0099eb377520ecd86af873555c133e644dad97acc6f6916d7c89a15bc95573a9a505d7ddcadc0d6e7dd5033f562e3f9bb92
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 `: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)
@@ -101,7 +102,8 @@ module MiniMagick
101
102
  @info["details"] ||= (
102
103
  details_string = identify(&:verbose)
103
104
  key_stack = []
104
- details_string.lines[1..-1].each_with_object({}) do |line, details_hash|
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
@@ -381,16 +387,12 @@ module MiniMagick
381
387
  #
382
388
  def method_missing(name, *args)
383
389
  mogrify do |builder|
384
- if builder.respond_to?(name)
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
- MiniMagick::Tool::Mogrify.new.respond_to?(method_name, include_private)
395
+ true
394
396
  end
395
397
 
396
398
  ##
@@ -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 = 5
11
+ MINOR = 3
12
+ TINY = 1
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.5
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-05-28 00:00:00.000000000 Z
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: