mini_magick 4.2.7 → 4.2.9

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.

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: 2ebe50720f44094421fa8d0f27a3a6934f69f70b
4
- data.tar.gz: 24d09b9541aa1c4bf258000147e1be96b9f3bdf3
3
+ metadata.gz: 40fe759f030711a8b4cae6a7334ba2c553f848a3
4
+ data.tar.gz: 37037fc7631d55294c20ad991dbc8f0bfb6c8fb2
5
5
  SHA512:
6
- metadata.gz: 42a75ad425fb787c4a7e74a25eaee6cb687df34e765e2e62a365f70a0f05d31763f486abc0274b127fac3a41b76c3bc9c031f477603ad482c0e309e2844f2b08
7
- data.tar.gz: dcba1f309e1a09759c6ffb6cc0aaf154d789d4c5ef9a9282d19a297e64844838af46654dd23648317721ea360170c8de90017ad6444b6082e8d15d7913f9b3fb
6
+ metadata.gz: 89c0deeaf8dc29605ac7651803be5af576822fcfa8485056254eec3710d31563a9f7d536b2f35d7e677d0b8ab9a4a35d5147aec18d0fba8e1fb9fbcb97f454b2
7
+ data.tar.gz: c553cc750c068c345fbc2757af7eb063e4d222102313f2a64930f9d67ff16adadfc636fe6b17b6377ce03bea0335f0f77d9a47ee6b7652ec02eb3cbf9b5eff28
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'
@@ -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)
@@ -131,7 +131,14 @@ module MiniMagick
131
131
  def cli=(value)
132
132
  @cli = value
133
133
 
134
- unless [:imagemagick, :graphicsmagick].include?(@cli)
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
135
142
  raise ArgumentError,
136
143
  "CLI has to be set to either :imagemagick or :graphicsmagick" \
137
144
  ", was set to #{@cli.inspect}"
@@ -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
@@ -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)
@@ -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,18 +15,6 @@ 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
18
  # @private
31
19
  def self.inherited(child)
32
20
  child_name = child.name.split("::").last.downcase
@@ -78,7 +66,7 @@ module MiniMagick
78
66
  # mogrify = MiniMagick::Tool::Mogrify.new
79
67
  # mogrify.resize("500x500")
80
68
  # mogrify << "path/to/image.jpg"
81
- # mogirfy.call # executes `mogrify -resize 500x500 path/to/image.jpg`
69
+ # mogrify.call # executes `mogrify -resize 500x500 path/to/image.jpg`
82
70
  #
83
71
  # @param whiny [Boolean] Whether you want an error to be raised when
84
72
  # ImageMagick returns an exit code of 1. You may want this because
@@ -87,9 +75,9 @@ module MiniMagick
87
75
  #
88
76
  # @return [String] Output of the command
89
77
  #
90
- def call(whiny = @whiny)
91
- shell = MiniMagick::Shell.new(whiny)
92
- shell.run(command).strip
78
+ def call(whiny = @whiny, options = {})
79
+ shell = MiniMagick::Shell.new
80
+ shell.run(command, options.merge(whiny: whiny)).strip
93
81
  end
94
82
 
95
83
  ##
@@ -224,7 +212,7 @@ module MiniMagick
224
212
  # mogrify.antialias
225
213
  # mogrify.depth(8)
226
214
  # mogrify.resize("500x500")
227
- # mogirfy.command.join(" ")
215
+ # mogrify.command.join(" ")
228
216
  # #=> "mogrify -antialias -depth 8 -resize 500x500"
229
217
  #
230
218
  def option(*options)
@@ -259,7 +247,9 @@ module MiniMagick
259
247
  end
260
248
 
261
249
  def cli_options
262
- help = MiniMagick::Tool.new(@tool_name, false) { |b| b << "-help" }
250
+ tool = MiniMagick::Tool.new(@tool_name)
251
+ tool << "-help"
252
+ help = tool.call(false, stderr: false)
263
253
  cli_options = help.scan(/^\s+-[a-z\-]+/).map(&:strip)
264
254
  end
265
255
 
@@ -267,3 +257,15 @@ module MiniMagick
267
257
 
268
258
  end
269
259
  end
260
+
261
+ require "mini_magick/tool/animate"
262
+ require "mini_magick/tool/compare"
263
+ require "mini_magick/tool/composite"
264
+ require "mini_magick/tool/conjure"
265
+ require "mini_magick/tool/convert"
266
+ require "mini_magick/tool/display"
267
+ require "mini_magick/tool/identify"
268
+ require "mini_magick/tool/import"
269
+ require "mini_magick/tool/mogrify"
270
+ require "mini_magick/tool/montage"
271
+ require "mini_magick/tool/stream"
@@ -9,7 +9,7 @@ module MiniMagick
9
9
  module VERSION
10
10
  MAJOR = 4
11
11
  MINOR = 2
12
- TINY = 7
12
+ TINY = 9
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
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.2.9
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-08-02 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: