mini_magick 4.0.2 → 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: f4305ecb6d70854a5e0d8108ea344872224b2d81
4
- data.tar.gz: 71e89af4b6640415d8d0f883b2ecbd660235493b
3
+ metadata.gz: 8921e089d8d63d1391e76876bc63b4e3ff953706
4
+ data.tar.gz: 38930195578ded9545d86b4225718671a9cd8b6a
5
5
  SHA512:
6
- metadata.gz: 7be3875ffe3ea305e0c4a87fa41644094240f7b3c1675c7d5c552f866a7d7ffdb56fecbc962974756e9eb91326c27917bddb57b06121e90161b9ca4b25204d52
7
- data.tar.gz: 116882e54bd0f9734a5eae2535b16c816073be328dd494ccece1714c7d7db3f4840d1df456bea8baded535e13b09faaff528c3790c0737485019ffe1ba0b61ef
6
+ metadata.gz: 39cc0fccd098a964a02be8e2cde7565d492ab9a5831df89a2f1b90d751d67368c13584c05ef3253aab51f8aecf107a52ca489a6849bd32e80a334869500f4628
7
+ data.tar.gz: 9c620a81d8b8e601a172d3b8333f4020048e2b7d385ce40fe85caff7f6df7480f1e08c8046d8fa10d66164eb264efe06d9303f111444f55c6193546ca34ab0f2
@@ -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
@@ -71,10 +72,20 @@ module MiniMagick
71
72
  #
72
73
  attr_accessor :whiny
73
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
+
74
84
  def self.extended(base)
75
85
  base.validate_on_create = true
76
86
  base.validate_on_write = true
77
87
  base.whiny = true
88
+ base.shell_api = "open3"
78
89
  end
79
90
 
80
91
  ##
@@ -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|
@@ -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
@@ -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 = 2
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.2
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: 2015-01-09 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