mini_magick 4.0.1 → 4.1.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: 7813127461ce5e5ca5f48e6a502672535afd76d4
4
- data.tar.gz: e82edbba8bb1af4fc07103cbaea62430f03fbb3f
3
+ metadata.gz: 8921e089d8d63d1391e76876bc63b4e3ff953706
4
+ data.tar.gz: 38930195578ded9545d86b4225718671a9cd8b6a
5
5
  SHA512:
6
- metadata.gz: 0fee195089d16cd7e8f3ac7b034c1569a7f353116966000698f18153f7c0fa5a4b71b2620375b460d02497521c5d275f68072e8b4960bfc87f9df64c0d2b2014
7
- data.tar.gz: da4fbde0cffd34084dd50340d4c8e8e51f5b26773b77370f856cc7aeb814e78ca605c053a055b54437bb9127e9c1fc0f631fd0eba581ca8e0b41d0b24217b5a5
6
+ metadata.gz: 39cc0fccd098a964a02be8e2cde7565d492ab9a5831df89a2f1b90d751d67368c13584c05ef3253aab51f8aecf107a52ca489a6849bd32e80a334869500f4628
7
+ data.tar.gz: 9c620a81d8b8e601a172d3b8333f4020048e2b7d385ce40fe85caff7f6df7480f1e08c8046d8fa10d66164eb264efe06d9303f111444f55c6193546ca34ab0f2
data/lib/mini_gmagick.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'mini_magick'
2
2
 
3
- MiniMagick.processor = :graphicsmagick
3
+ MiniMagick.processor = :gm
@@ -45,6 +45,7 @@ module MiniMagick
45
45
  # @return [Logger]
46
46
  #
47
47
  attr_accessor :logger
48
+
48
49
  ##
49
50
  # If set to `true`, it will `identify` every newly created image, and raise
50
51
  # `MiniMagick::Invalid` if the image is not valid. Useful for validating
@@ -63,9 +64,28 @@ module MiniMagick
63
64
  #
64
65
  attr_accessor :validate_on_write
65
66
 
67
+ ##
68
+ # If set to `false`, it will not raise errors when ImageMagick returns
69
+ # status code different than 0. Defaults to `true`.
70
+ #
71
+ # @return [Boolean]
72
+ #
73
+ attr_accessor :whiny
74
+
75
+ ##
76
+ # Instructs MiniMagick how to execute the shell commands. Available
77
+ # APIs are "open3" (default) and "posix-spawn" (requires the "posix-spawn"
78
+ # gem).
79
+ #
80
+ # @return [String]
81
+ #
82
+ attr_accessor :shell_api
83
+
66
84
  def self.extended(base)
67
85
  base.validate_on_create = true
68
86
  base.validate_on_write = true
87
+ base.whiny = true
88
+ base.shell_api = "open3"
69
89
  end
70
90
 
71
91
  ##
@@ -103,6 +123,8 @@ module MiniMagick
103
123
  case processor.to_s
104
124
  when "mogrify" then :imagemagick
105
125
  when "gm" then :graphicsmagick
126
+ else
127
+ raise MiniMagick::Error, "ImageMagick/GraphicsMagick is not installed"
106
128
  end
107
129
  end
108
130
 
@@ -80,10 +80,10 @@ module MiniMagick
80
80
  #
81
81
  def self.open(path_or_url, ext = nil)
82
82
  ext ||=
83
- if path_or_url.to_s =~ URI.regexp
84
- File.extname(URI(path_or_url).path)
85
- else
83
+ if File.exist?(path_or_url)
86
84
  File.extname(path_or_url)
85
+ else
86
+ File.extname(URI(path_or_url).path)
87
87
  end
88
88
 
89
89
  Kernel.open(path_or_url, "rb") do |file|
@@ -405,7 +405,7 @@ module MiniMagick
405
405
  builder << output_to
406
406
  end
407
407
  else
408
- FileUtils.copy_file path, output_to
408
+ FileUtils.copy_file path, output_to unless path == output_to.to_s
409
409
  end
410
410
  else
411
411
  IO.copy_stream File.open(path, "rb"), output_to
@@ -1,6 +1,4 @@
1
1
  require "mini_magick/logger"
2
-
3
- require "open3"
4
2
  require "timeout"
5
3
 
6
4
  module MiniMagick
@@ -35,14 +33,29 @@ module MiniMagick
35
33
  stdout, stderr, status =
36
34
  MiniMagick.logger.debug(command.join(" ")) do
37
35
  Timeout.timeout(MiniMagick.timeout) do
38
- Open3.capture3(*command)
36
+ send("execute_#{MiniMagick.shell_api.gsub("-", "_")}", *command)
39
37
  end
40
38
  end
41
39
 
42
40
  [stdout, stderr, status.exitstatus]
43
- rescue Errno::ENOENT
41
+ rescue Errno::ENOENT, IOError
44
42
  ["", "executable not found: \"#{command.first}\"", 127]
45
43
  end
46
44
 
45
+ private
46
+
47
+ def execute_open3(*command)
48
+ require "open3"
49
+ Open3.capture3(*command)
50
+ end
51
+
52
+ def execute_posix_spawn(*command)
53
+ require "posix-spawn"
54
+ pid, stdin, stdout, stderr = POSIX::Spawn.popen4(*command)
55
+ Process.waitpid(pid)
56
+
57
+ [stdout.read, stderr.read, $?]
58
+ end
59
+
47
60
  end
48
61
  end
@@ -65,7 +65,7 @@ module MiniMagick
65
65
  # MiniMagick::Tool::Identify.new(false) do |identify|
66
66
  # identify.help # returns exit status 1, which would otherwise throw an error
67
67
  # end
68
- def initialize(name, whiny = true)
68
+ def initialize(name, whiny = MiniMagick.whiny)
69
69
  @name = name
70
70
  @whiny = whiny
71
71
  @args = []
@@ -149,10 +149,11 @@ module MiniMagick
149
149
  # Changes the last operator to its "plus" form.
150
150
  #
151
151
  # @example
152
- # mogrify = MiniMagick::Tool::Mogrify.new
153
- # mogrify.antialias.+
154
- # mogrify.distort.+("Perspective '0,0,4,5'")
155
- # mogrify.command #=> ["mogrify", "+antialias", "+distort", "Perspective '0,0,4,5'"]
152
+ # MiniMagick::Tool::Mogrify.new do |mogrify|
153
+ # mogrify.antialias.+
154
+ # mogrify.distort.+("Perspective", "0,0,4,5 89,0,45,46")
155
+ # end
156
+ # # executes `mogrify +antialias +distort Perspective '0,0,4,5 89,0,45,46'`
156
157
  #
157
158
  # @return [self]
158
159
  #
@@ -162,6 +163,27 @@ module MiniMagick
162
163
  self
163
164
  end
164
165
 
166
+ ##
167
+ # Create an ImageMagick stack in the command (surround.
168
+ #
169
+ # @example
170
+ # MiniMagick::Tool::Convert.new do |convert|
171
+ # convert << "wand.gif"
172
+ # convert.stack do |stack|
173
+ # stack << "wand.gif"
174
+ # stack.rotate(30)
175
+ # end
176
+ # convert.append.+
177
+ # convert << "images.gif"
178
+ # end
179
+ # # executes `convert wand.gif \( wizard.gif -rotate 30 \) +append images.gif`
180
+ #
181
+ def stack
182
+ self << "("
183
+ yield self
184
+ self << ")"
185
+ end
186
+
165
187
  private
166
188
 
167
189
  ##
@@ -202,11 +224,12 @@ module MiniMagick
202
224
  ##
203
225
  # Creates method based on command-line option's name.
204
226
  #
205
- # mogrify = MiniMagick::Tool.new("mogrify")
206
- # mogrify.antialias
207
- # mogrify.depth(8)
208
- # mogrify.resize("500x500")
209
- # mogirfy.command.join(" ") #=> "mogrify -antialias -depth "8" -resize "500x500""
227
+ # mogrify = MiniMagick::Tool.new("mogrify")
228
+ # mogrify.antialias
229
+ # mogrify.depth(8)
230
+ # mogrify.resize("500x500")
231
+ # mogirfy.command.join(" ")
232
+ # #=> "mogrify -antialias -depth 8 -resize 500x500"
210
233
  #
211
234
  def option(*options)
212
235
  options.each do |option|
@@ -8,8 +8,8 @@ module MiniMagick
8
8
 
9
9
  module VERSION
10
10
  MAJOR = 4
11
- MINOR = 0
12
- TINY = 1
11
+ MINOR = 1
12
+ TINY = 0
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.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Johnson
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-11-23 00:00:00.000000000 Z
15
+ date: 2015-02-17 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rake
@@ -42,6 +42,20 @@ dependencies:
42
42
  - - "~>"
43
43
  - !ruby/object:Gem::Version
44
44
  version: 3.1.0
45
+ - !ruby/object:Gem::Dependency
46
+ name: posix-spawn
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
45
59
  description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
46
60
  email:
47
61
  - probablycorey@gmail.com
@@ -97,8 +111,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
111
  requirements:
98
112
  - You must have ImageMagick or GraphicsMagick installed
99
113
  rubyforge_project:
100
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.4.5
101
115
  signing_key:
102
116
  specification_version: 4
103
117
  summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
104
118
  test_files: []
119
+ has_rdoc: