mini_magick 4.0.2 → 4.2.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 +4 -4
- data/lib/mini_magick/configuration.rb +11 -0
- data/lib/mini_magick/image/info.rb +33 -16
- data/lib/mini_magick/image.rb +9 -4
- data/lib/mini_magick/shell.rb +17 -4
- data/lib/mini_magick/tool.rb +32 -9
- data/lib/mini_magick/version.rb +2 -2
- metadata +18 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 21f140f463e39c25ff85d153dde2633ae64253fc
|
|
4
|
+
data.tar.gz: 09fcec5741441ab2b4d7f8346ddfa2d6d5c40a51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6daee1a467de3117d0278a79d6006446c35bcf64afc746fa7ae04a45ee53b26334c171d7f73e58e0de97792496d82e4a00c336511e62427c55bb97e67f278f40
|
|
7
|
+
data.tar.gz: 87a1ccb4e52bbfd6fcfe4f4251f4d6711dd79aaa4d935b10d35c04db27ff11236dfca5422efb67c704c6953e54939751d4419cf1ca9d0bc63d91787b473ad3d3
|
|
@@ -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
|
##
|
|
@@ -25,6 +25,8 @@ module MiniMagick
|
|
|
25
25
|
raw_exif(value)
|
|
26
26
|
when "exif"
|
|
27
27
|
exif
|
|
28
|
+
when "details"
|
|
29
|
+
details
|
|
28
30
|
else
|
|
29
31
|
raw(value)
|
|
30
32
|
end
|
|
@@ -53,9 +55,7 @@ module MiniMagick
|
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
def colorspace
|
|
56
|
-
@info
|
|
57
|
-
@info["colorspace"] = self["%r"]
|
|
58
|
-
end
|
|
58
|
+
@info["colorspace"] ||= self["%r"]
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def mime_type
|
|
@@ -75,10 +75,10 @@ module MiniMagick
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def exif
|
|
78
|
-
@info
|
|
78
|
+
@info["exif"] ||= (
|
|
79
79
|
output = self["%[EXIF:*]"]
|
|
80
80
|
pairs = output.gsub(/^exif:/, "").split("\n").map { |line| line.split("=") }
|
|
81
|
-
|
|
81
|
+
Hash[pairs].tap do |hash|
|
|
82
82
|
ASCII_ENCODED_EXIF_KEYS.each do |key|
|
|
83
83
|
next unless hash.has_key?(key)
|
|
84
84
|
|
|
@@ -86,22 +86,40 @@ module MiniMagick
|
|
|
86
86
|
hash[key] = decode_comma_separated_ascii_characters(value)
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
|
-
|
|
90
|
-
@info["exif"] = exif
|
|
91
|
-
end
|
|
89
|
+
)
|
|
92
90
|
end
|
|
93
91
|
|
|
94
92
|
def raw(value)
|
|
95
|
-
|
|
96
|
-
@info.fetch(key) do
|
|
97
|
-
@info[key] = identify { |b| b.format(value) }
|
|
98
|
-
end
|
|
93
|
+
@info["raw:#{value}"] ||= identify { |b| b.format(value) }
|
|
99
94
|
end
|
|
100
95
|
|
|
101
96
|
def signature
|
|
102
|
-
@info
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
@info["signature"] ||= self["%#"]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def details
|
|
101
|
+
@info["details"] ||= (
|
|
102
|
+
details_string = identify(&:verbose)
|
|
103
|
+
details_string.each_line.with_object([]).inject({}) do |details_hash, (line, key_stack)|
|
|
104
|
+
level = line[/^\s*/].length / 2 - 1
|
|
105
|
+
next details_hash if level == -1 # we ignore the root level
|
|
106
|
+
hash = key_stack.inject(details_hash) { |hash, key| hash.fetch(key) }
|
|
107
|
+
key, value = line.split(":", 2).map(&:strip)
|
|
108
|
+
|
|
109
|
+
if level == key_stack.size
|
|
110
|
+
if value.empty?
|
|
111
|
+
hash[key] = {}
|
|
112
|
+
key_stack.push key
|
|
113
|
+
else
|
|
114
|
+
hash[key] = value
|
|
115
|
+
end
|
|
116
|
+
elsif level < key_stack.size
|
|
117
|
+
key_stack.pop
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
details_hash
|
|
121
|
+
end
|
|
122
|
+
)
|
|
105
123
|
end
|
|
106
124
|
|
|
107
125
|
def identify
|
|
@@ -113,7 +131,6 @@ module MiniMagick
|
|
|
113
131
|
|
|
114
132
|
def decode_comma_separated_ascii_characters(encoded_value)
|
|
115
133
|
return encoded_value unless encoded_value.include?(',')
|
|
116
|
-
|
|
117
134
|
encoded_value.scan(/\d+/).map(&:to_i).map(&:chr).join
|
|
118
135
|
end
|
|
119
136
|
|
data/lib/mini_magick/image.rb
CHANGED
|
@@ -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
|
|
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|
|
|
@@ -258,6 +258,11 @@ module MiniMagick
|
|
|
258
258
|
# @return [String]
|
|
259
259
|
#
|
|
260
260
|
attribute :signature
|
|
261
|
+
##
|
|
262
|
+
# Returns the information from `identify -verbose` in a Hash format.
|
|
263
|
+
#
|
|
264
|
+
# @return [Hash]
|
|
265
|
+
attribute :details
|
|
261
266
|
|
|
262
267
|
##
|
|
263
268
|
# Use this method if you want to access raw Identify's format API.
|
|
@@ -424,7 +429,7 @@ module MiniMagick
|
|
|
424
429
|
#
|
|
425
430
|
# @see http://www.imagemagick.org/script/composite.php
|
|
426
431
|
#
|
|
427
|
-
def composite(other_image, output_extension =
|
|
432
|
+
def composite(other_image, output_extension = type.downcase, mask = nil)
|
|
428
433
|
output_tempfile = MiniMagick::Utilities.tempfile(".#{output_extension}")
|
|
429
434
|
|
|
430
435
|
MiniMagick::Tool::Composite.new do |composite|
|
data/lib/mini_magick/shell.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/mini_magick/tool.rb
CHANGED
|
@@ -149,10 +149,11 @@ module MiniMagick
|
|
|
149
149
|
# Changes the last operator to its "plus" form.
|
|
150
150
|
#
|
|
151
151
|
# @example
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
155
|
-
#
|
|
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
|
-
#
|
|
206
|
-
#
|
|
207
|
-
#
|
|
208
|
-
#
|
|
209
|
-
#
|
|
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|
|
data/lib/mini_magick/version.rb
CHANGED
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
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Corey Johnson
|
|
@@ -9,10 +9,11 @@ authors:
|
|
|
9
9
|
- Peter Kieltyka
|
|
10
10
|
- James Miller
|
|
11
11
|
- Thiago Fernandes Massa
|
|
12
|
+
- Janko Marohnić
|
|
12
13
|
autorequire:
|
|
13
14
|
bindir: bin
|
|
14
15
|
cert_chain: []
|
|
15
|
-
date: 2015-
|
|
16
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
|
16
17
|
dependencies:
|
|
17
18
|
- !ruby/object:Gem::Dependency
|
|
18
19
|
name: rake
|
|
@@ -42,6 +43,20 @@ dependencies:
|
|
|
42
43
|
- - "~>"
|
|
43
44
|
- !ruby/object:Gem::Version
|
|
44
45
|
version: 3.1.0
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: posix-spawn
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0'
|
|
53
|
+
type: :development
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
45
60
|
description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
|
46
61
|
email:
|
|
47
62
|
- probablycorey@gmail.com
|
|
@@ -49,6 +64,7 @@ email:
|
|
|
49
64
|
- peter@nulayer.com
|
|
50
65
|
- bensie@gmail.com
|
|
51
66
|
- thiagown@gmail.com
|
|
67
|
+
- janko.marohnic@gmail.com
|
|
52
68
|
executables: []
|
|
53
69
|
extensions: []
|
|
54
70
|
extra_rdoc_files: []
|