mini_magick 4.11.0 → 5.3.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/README.md +558 -0
- data/lib/mini_magick/configuration.rb +39 -128
- data/lib/mini_magick/image/info.rb +9 -60
- data/lib/mini_magick/image.rb +49 -74
- data/lib/mini_magick/shell.rb +22 -50
- data/lib/mini_magick/tool.rb +44 -77
- data/lib/mini_magick/utilities.rb +4 -6
- data/lib/mini_magick/version.rb +2 -2
- data/lib/mini_magick.rb +18 -42
- metadata +18 -75
- data/lib/mini_gmagick.rb +0 -3
- data/lib/mini_magick/tool/animate.rb +0 -14
- data/lib/mini_magick/tool/compare.rb +0 -14
- data/lib/mini_magick/tool/composite.rb +0 -14
- data/lib/mini_magick/tool/conjure.rb +0 -14
- data/lib/mini_magick/tool/convert.rb +0 -14
- data/lib/mini_magick/tool/display.rb +0 -14
- data/lib/mini_magick/tool/identify.rb +0 -14
- data/lib/mini_magick/tool/import.rb +0 -14
- data/lib/mini_magick/tool/magick.rb +0 -14
- data/lib/mini_magick/tool/mogrify.rb +0 -14
- data/lib/mini_magick/tool/mogrify_restricted.rb +0 -15
- data/lib/mini_magick/tool/montage.rb +0 -14
- data/lib/mini_magick/tool/stream.rb +0 -14
@@ -5,12 +5,11 @@ module MiniMagick
|
|
5
5
|
module Configuration
|
6
6
|
|
7
7
|
##
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# Uses [GraphicsMagick](http://www.graphicsmagick.org/) instead of
|
9
|
+
# ImageMagick, by prefixing commands with `gm` instead of `magick`.
|
10
10
|
#
|
11
|
-
|
12
|
-
|
13
|
-
attr_accessor :processor_path
|
11
|
+
# @return [Boolean]
|
12
|
+
attr_accessor :graphicsmagick
|
14
13
|
|
15
14
|
##
|
16
15
|
# Adds a prefix to the CLI command.
|
@@ -24,45 +23,46 @@ module MiniMagick
|
|
24
23
|
attr_accessor :cli_prefix
|
25
24
|
|
26
25
|
##
|
27
|
-
#
|
28
|
-
#
|
26
|
+
# Adds environment variables to every CLI command call.
|
27
|
+
# For example, you could use it to set `LD_PRELOAD="/path/to/libsomething.so"`.
|
28
|
+
# Must be a hash of strings keyed to valid environment variable name strings.
|
29
|
+
# e.g. {'MY_ENV' => 'my value'}
|
29
30
|
#
|
30
|
-
# @return [
|
31
|
+
# @return [Hash]
|
31
32
|
#
|
32
|
-
attr_accessor :
|
33
|
+
attr_accessor :cli_env
|
34
|
+
|
33
35
|
##
|
34
|
-
#
|
35
|
-
#
|
36
|
+
# If set to true, Open3 will restrict system calls to access only
|
37
|
+
# environment variables defined in :cli_env, plus HOME, PATH, and LANG
|
38
|
+
# since those are required for such system calls. It will not pass on any
|
39
|
+
# other environment variables from the system.
|
36
40
|
#
|
37
41
|
# @return [Boolean]
|
38
42
|
#
|
39
|
-
|
43
|
+
attr_accessor :restricted_env
|
44
|
+
|
40
45
|
##
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# a file.
|
46
|
+
# If you don't want commands to take too long, you can set a timeout (in
|
47
|
+
# seconds).
|
44
48
|
#
|
45
|
-
# @return [
|
49
|
+
# @return [Integer]
|
46
50
|
#
|
47
|
-
attr_accessor :
|
48
|
-
|
51
|
+
attr_accessor :timeout
|
49
52
|
##
|
50
|
-
#
|
51
|
-
#
|
52
|
-
# user input, although it adds a bit of overhead. Defaults to `true`.
|
53
|
+
# Logger for commands, default is `Logger.new($stdout)`, but you can
|
54
|
+
# override it, for example if you want the logs to be written to a file.
|
53
55
|
#
|
54
|
-
# @return [
|
56
|
+
# @return [Logger]
|
55
57
|
#
|
56
|
-
attr_accessor :
|
58
|
+
attr_accessor :logger
|
57
59
|
##
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# is not valid. Useful for validating that processing was sucessful,
|
61
|
-
# although it adds a bit of overhead. Defaults to `true`.
|
60
|
+
# Temporary directory used by MiniMagick, default is `Dir.tmpdir`, but
|
61
|
+
# you can override it.
|
62
62
|
#
|
63
|
-
# @return [
|
63
|
+
# @return [String]
|
64
64
|
#
|
65
|
-
attr_accessor :
|
65
|
+
attr_accessor :tmpdir
|
66
66
|
|
67
67
|
##
|
68
68
|
# If set to `false`, it will not raise errors when ImageMagick returns
|
@@ -70,121 +70,32 @@ module MiniMagick
|
|
70
70
|
#
|
71
71
|
# @return [Boolean]
|
72
72
|
#
|
73
|
-
attr_accessor :
|
73
|
+
attr_accessor :errors
|
74
74
|
|
75
75
|
##
|
76
|
-
#
|
77
|
-
#
|
78
|
-
|
79
|
-
#
|
80
|
-
# @return [String]
|
81
|
-
#
|
82
|
-
attr_accessor :shell_api
|
76
|
+
# If set to `false`, it will not forward warnings from ImageMagick to
|
77
|
+
# standard error.
|
78
|
+
attr_accessor :warnings
|
83
79
|
|
84
80
|
def self.extended(base)
|
85
|
-
base.
|
86
|
-
base.
|
87
|
-
base.whiny = true
|
88
|
-
base.shell_api = "open3"
|
81
|
+
base.tmpdir = Dir.tmpdir
|
82
|
+
base.errors = true
|
89
83
|
base.logger = Logger.new($stdout).tap { |l| l.level = Logger::INFO }
|
84
|
+
base.warnings = true
|
85
|
+
base.cli_env = {}.freeze
|
86
|
+
base.restricted_env = false
|
87
|
+
base.graphicsmagick = false
|
90
88
|
end
|
91
89
|
|
92
90
|
##
|
93
91
|
# @yield [self]
|
94
92
|
# @example
|
95
93
|
# MiniMagick.configure do |config|
|
96
|
-
# config.cli = :graphicsmagick
|
97
94
|
# config.timeout = 5
|
98
95
|
# end
|
99
96
|
#
|
100
97
|
def configure
|
101
98
|
yield self
|
102
99
|
end
|
103
|
-
|
104
|
-
CLI_DETECTION = {
|
105
|
-
imagemagick7: "magick",
|
106
|
-
imagemagick: "mogrify",
|
107
|
-
graphicsmagick: "gm",
|
108
|
-
}
|
109
|
-
|
110
|
-
# @private (for backwards compatibility)
|
111
|
-
def processor
|
112
|
-
@processor ||= CLI_DETECTION.values.detect do |processor|
|
113
|
-
MiniMagick::Utilities.which(processor)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# @private (for backwards compatibility)
|
118
|
-
def processor=(processor)
|
119
|
-
@processor = processor.to_s
|
120
|
-
|
121
|
-
unless CLI_DETECTION.value?(@processor)
|
122
|
-
raise ArgumentError,
|
123
|
-
"processor has to be set to either \"magick\", \"mogrify\" or \"gm\"" \
|
124
|
-
", was set to #{@processor.inspect}"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
##
|
129
|
-
# Get [ImageMagick](http://www.imagemagick.org) or
|
130
|
-
# [GraphicsMagick](http://www.graphicsmagick.org).
|
131
|
-
#
|
132
|
-
# @return [Symbol] `:imagemagick` or `:graphicsmagick`
|
133
|
-
#
|
134
|
-
def cli
|
135
|
-
if instance_variable_defined?("@cli")
|
136
|
-
instance_variable_get("@cli")
|
137
|
-
else
|
138
|
-
cli = CLI_DETECTION.key(processor) or
|
139
|
-
fail MiniMagick::Error, "You must have ImageMagick or GraphicsMagick installed"
|
140
|
-
|
141
|
-
instance_variable_set("@cli", cli)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
##
|
146
|
-
# Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
|
147
|
-
# [GraphicsMagick](http://www.graphicsmagick.org).
|
148
|
-
#
|
149
|
-
def cli=(value)
|
150
|
-
@cli = value
|
151
|
-
|
152
|
-
if not CLI_DETECTION.key?(@cli)
|
153
|
-
raise ArgumentError,
|
154
|
-
"CLI has to be set to either :imagemagick, :imagemagick7 or :graphicsmagick" \
|
155
|
-
", was set to #{@cli.inspect}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
##
|
160
|
-
# If you set the path of CLI tools, you can get the path of the
|
161
|
-
# executables.
|
162
|
-
#
|
163
|
-
# @return [String]
|
164
|
-
#
|
165
|
-
def cli_path
|
166
|
-
if instance_variable_defined?("@cli_path")
|
167
|
-
instance_variable_get("@cli_path")
|
168
|
-
else
|
169
|
-
processor_path = instance_variable_get("@processor_path") if instance_variable_defined?("@processor_path")
|
170
|
-
|
171
|
-
instance_variable_set("@cli_path", processor_path)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
##
|
176
|
-
# When set to `true`, it outputs each command to STDOUT in their shell
|
177
|
-
# version.
|
178
|
-
#
|
179
|
-
def debug=(value)
|
180
|
-
warn "MiniMagick.debug is deprecated and will be removed in MiniMagick 5. Use `MiniMagick.logger.level = Logger::DEBUG` instead."
|
181
|
-
logger.level = value ? Logger::DEBUG : Logger::INFO
|
182
|
-
end
|
183
|
-
|
184
|
-
# Backwards compatibility
|
185
|
-
def reload_tools
|
186
|
-
warn "MiniMagick.reload_tools is deprecated because it is no longer necessary"
|
187
|
-
end
|
188
|
-
|
189
100
|
end
|
190
101
|
end
|
@@ -17,8 +17,6 @@ module MiniMagick
|
|
17
17
|
cheap_info(value)
|
18
18
|
when "colorspace"
|
19
19
|
colorspace
|
20
|
-
when "mime_type"
|
21
|
-
mime_type
|
22
20
|
when "resolution"
|
23
21
|
resolution(*args)
|
24
22
|
when "signature"
|
@@ -27,8 +25,6 @@ module MiniMagick
|
|
27
25
|
raw_exif(value)
|
28
26
|
when "exif"
|
29
27
|
exif
|
30
|
-
when "details"
|
31
|
-
details
|
32
28
|
when "data"
|
33
29
|
data
|
34
30
|
else
|
@@ -61,13 +57,13 @@ module MiniMagick
|
|
61
57
|
rescue ArgumentError, TypeError
|
62
58
|
raise MiniMagick::Invalid, "image data can't be read"
|
63
59
|
end
|
64
|
-
|
60
|
+
|
65
61
|
def parse_warnings(raw_info)
|
66
62
|
return raw_info unless raw_info.split("\n").size > 1
|
67
63
|
|
68
64
|
raw_info.split("\n").each do |line|
|
69
65
|
# must match "%m %w %h %b"
|
70
|
-
return line if line.match?
|
66
|
+
return line if line.match?(/^[A-Z]+ \d+ \d+ \d+(|\.\d+)([KMGTPEZY]{0,1})B$/)
|
71
67
|
end
|
72
68
|
raise TypeError
|
73
69
|
end
|
@@ -76,10 +72,6 @@ module MiniMagick
|
|
76
72
|
@info["colorspace"] ||= self["%r"]
|
77
73
|
end
|
78
74
|
|
79
|
-
def mime_type
|
80
|
-
"image/#{self["format"].downcase}"
|
81
|
-
end
|
82
|
-
|
83
75
|
def resolution(unit = nil)
|
84
76
|
output = identify do |b|
|
85
77
|
b.units unit if unit
|
@@ -100,20 +92,12 @@ module MiniMagick
|
|
100
92
|
output.each_line do |line|
|
101
93
|
line = line.chomp("\n")
|
102
94
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
key, value = match.post_match.split("=", 2)
|
107
|
-
value = decode_comma_separated_ascii_characters(value) if ASCII_ENCODED_EXIF_KEYS.include?(key)
|
108
|
-
hash[key] = value
|
109
|
-
else
|
110
|
-
hash[hash.keys.last] << "\n#{line}"
|
111
|
-
end
|
112
|
-
when :graphicsmagick
|
113
|
-
next if line == "unknown"
|
114
|
-
key, value = line.split("=", 2)
|
115
|
-
value.gsub!("\\012", "\n") # convert "\012" characters to newlines
|
95
|
+
if match = line.match(/^exif:/)
|
96
|
+
key, value = match.post_match.split("=", 2)
|
97
|
+
value = decode_comma_separated_ascii_characters(value) if ASCII_ENCODED_EXIF_KEYS.include?(key)
|
116
98
|
hash[key] = value
|
99
|
+
else
|
100
|
+
hash[hash.keys.last] << "\n#{line}"
|
117
101
|
end
|
118
102
|
end
|
119
103
|
|
@@ -129,44 +113,9 @@ module MiniMagick
|
|
129
113
|
@info["signature"] ||= self["%#"]
|
130
114
|
end
|
131
115
|
|
132
|
-
def details
|
133
|
-
warn "[MiniMagick] MiniMagick::Image#details has been deprecated, as it was causing too many parsing errors. You should use MiniMagick::Image#data instead, which differs in a way that the keys are in camelcase." if MiniMagick.imagemagick? || MiniMagick.imagemagick7?
|
134
|
-
|
135
|
-
@info["details"] ||= (
|
136
|
-
details_string = identify(&:verbose)
|
137
|
-
key_stack = []
|
138
|
-
details_string.lines.to_a[1..-1].each_with_object({}) do |line, details_hash|
|
139
|
-
next if !line.valid_encoding? || line.strip.length.zero?
|
140
|
-
|
141
|
-
level = line[/^\s*/].length / 2 - 1
|
142
|
-
if level >= 0
|
143
|
-
key_stack.pop until key_stack.size <= level
|
144
|
-
else
|
145
|
-
# Some metadata, such as SVG clipping paths, will be saved without
|
146
|
-
# indentation, resulting in a level of -1
|
147
|
-
last_key = details_hash.keys.last
|
148
|
-
details_hash[last_key] = '' if details_hash[last_key].empty?
|
149
|
-
details_hash[last_key] << line
|
150
|
-
next
|
151
|
-
end
|
152
|
-
|
153
|
-
key, _, value = line.partition(/:[\s]/).map(&:strip)
|
154
|
-
hash = key_stack.inject(details_hash) { |_hash, _key| _hash.fetch(_key) }
|
155
|
-
if value.empty?
|
156
|
-
hash[key] = {}
|
157
|
-
key_stack.push key
|
158
|
-
else
|
159
|
-
hash[key] = value
|
160
|
-
end
|
161
|
-
end
|
162
|
-
)
|
163
|
-
end
|
164
|
-
|
165
116
|
def data
|
166
|
-
raise Error, "MiniMagick::Image#data isn't supported on GraphicsMagick. Use MiniMagick::Image#details instead." if MiniMagick.graphicsmagick?
|
167
|
-
|
168
117
|
@info["data"] ||= (
|
169
|
-
json = MiniMagick
|
118
|
+
json = MiniMagick.convert do |convert|
|
170
119
|
convert << path
|
171
120
|
convert << "json:"
|
172
121
|
end
|
@@ -178,7 +127,7 @@ module MiniMagick
|
|
178
127
|
end
|
179
128
|
|
180
129
|
def identify
|
181
|
-
MiniMagick
|
130
|
+
MiniMagick.identify do |builder|
|
182
131
|
yield builder if block_given?
|
183
132
|
builder << path
|
184
133
|
end
|
data/lib/mini_magick/image.rb
CHANGED
@@ -51,11 +51,11 @@ module MiniMagick
|
|
51
51
|
#
|
52
52
|
def self.import_pixels(blob, columns, rows, depth, map, format = 'png')
|
53
53
|
# Create an image object with the raw pixel data string:
|
54
|
-
|
54
|
+
read(blob, ".dat").tap do |image|
|
55
55
|
output_path = image.path.sub(/\.\w+$/, ".#{format}")
|
56
56
|
# Use ImageMagick to convert the raw data file to an image file of the
|
57
57
|
# desired format:
|
58
|
-
MiniMagick
|
58
|
+
MiniMagick.convert do |convert|
|
59
59
|
convert.size "#{columns}x#{rows}"
|
60
60
|
convert.depth depth
|
61
61
|
convert << "#{map}:#{image.path}"
|
@@ -79,33 +79,15 @@ module MiniMagick
|
|
79
79
|
# @param options [Hash] Specify options for the open method
|
80
80
|
# @return [MiniMagick::Image] The loaded image
|
81
81
|
#
|
82
|
-
def self.open(path_or_url, ext = nil, options
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if path_or_url.respond_to?(:open)
|
88
|
-
path_or_url
|
89
|
-
elsif path_or_url.respond_to?(:to_str) &&
|
90
|
-
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ path_or_url &&
|
91
|
-
(uri = URI.parse(path_or_url)).respond_to?(:open)
|
92
|
-
uri
|
93
|
-
else
|
94
|
-
options = { binmode: true }.merge(options)
|
95
|
-
Pathname(path_or_url)
|
96
|
-
end
|
97
|
-
|
98
|
-
if openable.is_a?(URI::Generic)
|
99
|
-
ext ||= File.extname(openable.path)
|
100
|
-
else
|
101
|
-
ext ||= File.extname(openable.to_s)
|
102
|
-
end
|
103
|
-
ext.sub!(/:.*/, '') # hack for filenames or URLs that include a colon
|
104
|
-
|
105
|
-
if openable.is_a?(URI::Generic)
|
106
|
-
openable.open(options) { |file| read(file, ext) }
|
82
|
+
def self.open(path_or_url, ext = nil, **options)
|
83
|
+
if path_or_url.to_s =~ %r{\A(https?|ftp)://}
|
84
|
+
uri = URI(path_or_url)
|
85
|
+
ext ||= File.extname(uri.path).sub(/:.*/, '') # handle URL including a colon
|
86
|
+
uri.open(options) { |file| read(file, ext) }
|
107
87
|
else
|
108
|
-
|
88
|
+
pathname = Pathname(path_or_url)
|
89
|
+
ext ||= File.extname(pathname.to_s)
|
90
|
+
pathname.open(binmode: true, **options) { |file| read(file, ext) }
|
109
91
|
end
|
110
92
|
end
|
111
93
|
|
@@ -118,18 +100,14 @@ module MiniMagick
|
|
118
100
|
# we have a good tempfile.
|
119
101
|
#
|
120
102
|
# @param ext [String] Specify the extension you want to read it as
|
121
|
-
# @param validate [Boolean] If false, skips validation of the created
|
122
|
-
# image. Defaults to true.
|
123
103
|
# @yield [Tempfile] You can #write bits to this object to create the new
|
124
104
|
# Image
|
125
105
|
# @return [MiniMagick::Image] The created image
|
126
106
|
#
|
127
|
-
def self.create(ext = nil,
|
107
|
+
def self.create(ext = nil, &block)
|
128
108
|
tempfile = MiniMagick::Utilities.tempfile(ext.to_s.downcase, &block)
|
129
109
|
|
130
|
-
new(tempfile.path, tempfile)
|
131
|
-
image.validate! if validate
|
132
|
-
end
|
110
|
+
new(tempfile.path, tempfile)
|
133
111
|
end
|
134
112
|
|
135
113
|
##
|
@@ -164,7 +142,7 @@ module MiniMagick
|
|
164
142
|
# which creates a temporary file for you and protects your original.
|
165
143
|
#
|
166
144
|
# @param input_path [String, Pathname] The location of an image file
|
167
|
-
# @yield [MiniMagick::Tool
|
145
|
+
# @yield [MiniMagick::Tool] If block is given, {#combine_options}
|
168
146
|
# is called.
|
169
147
|
#
|
170
148
|
def initialize(input_path, tempfile = nil, &block)
|
@@ -228,10 +206,6 @@ module MiniMagick
|
|
228
206
|
#
|
229
207
|
attribute :type, "format"
|
230
208
|
##
|
231
|
-
# @return [String]
|
232
|
-
#
|
233
|
-
attribute :mime_type
|
234
|
-
##
|
235
209
|
# @return [Integer]
|
236
210
|
#
|
237
211
|
attribute :width
|
@@ -274,7 +248,7 @@ module MiniMagick
|
|
274
248
|
#
|
275
249
|
attribute :resolution
|
276
250
|
##
|
277
|
-
# Returns the message digest of this image as a SHA-256,
|
251
|
+
# Returns the message digest of this image as a SHA-256, hexadecimal
|
278
252
|
# encoded string. This signature uniquely identifies the image and is
|
279
253
|
# convenient for determining if an image has been modified or whether two
|
280
254
|
# images are identical.
|
@@ -286,17 +260,10 @@ module MiniMagick
|
|
286
260
|
#
|
287
261
|
attribute :signature
|
288
262
|
##
|
289
|
-
# Returns the
|
290
|
-
# ImageMagick.
|
263
|
+
# Returns the result of converting the image to JSON format.
|
291
264
|
#
|
292
265
|
# @return [Hash]
|
293
266
|
attribute :data
|
294
|
-
##
|
295
|
-
# Returns the information from `identify -verbose` in a Hash format, for
|
296
|
-
# GraphicsMagick.
|
297
|
-
#
|
298
|
-
# @return [Hash]
|
299
|
-
attribute :details
|
300
267
|
|
301
268
|
##
|
302
269
|
# Use this method if you want to access raw Identify's format API.
|
@@ -340,13 +307,18 @@ module MiniMagick
|
|
340
307
|
#
|
341
308
|
# 1) one for each row of pixels
|
342
309
|
# 2) one for each column of pixels
|
343
|
-
# 3) three elements in the range 0-255, one for each of the RGB color channels
|
310
|
+
# 3) three or four elements in the range 0-255, one for each of the RGB(A) color channels
|
344
311
|
#
|
345
312
|
# @example
|
346
313
|
# img = MiniMagick::Image.open 'image.jpg'
|
347
314
|
# pixels = img.get_pixels
|
348
315
|
# pixels[3][2][1] # the green channel value from the 4th-row, 3rd-column pixel
|
349
316
|
#
|
317
|
+
# @example
|
318
|
+
# img = MiniMagick::Image.open 'image.jpg'
|
319
|
+
# pixels = img.get_pixels("RGBA")
|
320
|
+
# pixels[3][2][3] # the alpha channel value from the 4th-row, 3rd-column pixel
|
321
|
+
#
|
350
322
|
# It can also be called after applying transformations:
|
351
323
|
#
|
352
324
|
# @example
|
@@ -357,19 +329,22 @@ module MiniMagick
|
|
357
329
|
#
|
358
330
|
# In this example, all pixels in pix should now have equal R, G, and B values.
|
359
331
|
#
|
332
|
+
# @param map [String] A code for the mapping of the pixel data. Must be either
|
333
|
+
# 'RGB' or 'RGBA'. Default to 'RGB'
|
360
334
|
# @return [Array] Matrix of each color of each pixel
|
361
|
-
def get_pixels
|
362
|
-
|
335
|
+
def get_pixels(map="RGB")
|
336
|
+
raise ArgumentError, "Invalid map value" unless ["RGB", "RGBA"].include?(map)
|
337
|
+
convert = MiniMagick.convert
|
363
338
|
convert << path
|
364
339
|
convert.depth(8)
|
365
|
-
convert << "
|
340
|
+
convert << "#{map}:-"
|
366
341
|
|
367
342
|
# Do not use `convert.call` here. We need the whole binary (unstripped) output here.
|
368
343
|
shell = MiniMagick::Shell.new
|
369
344
|
output, * = shell.run(convert.command)
|
370
345
|
|
371
346
|
pixels_array = output.unpack("C*")
|
372
|
-
pixels = pixels_array.each_slice(
|
347
|
+
pixels = pixels_array.each_slice(map.length).each_slice(width).to_a
|
373
348
|
|
374
349
|
# deallocate large intermediary objects
|
375
350
|
output.clear
|
@@ -389,10 +364,10 @@ module MiniMagick
|
|
389
364
|
# @example
|
390
365
|
# # It is given in readme.md file
|
391
366
|
##
|
392
|
-
def self.get_image_from_pixels(pixels, dimension, map, depth,
|
367
|
+
def self.get_image_from_pixels(pixels, dimension, map, depth, format)
|
393
368
|
pixels = pixels.flatten
|
394
369
|
blob = pixels.pack('C*')
|
395
|
-
import_pixels(blob, *dimension, depth, map,
|
370
|
+
import_pixels(blob, *dimension, depth, map, format)
|
396
371
|
end
|
397
372
|
|
398
373
|
##
|
@@ -418,7 +393,7 @@ module MiniMagick
|
|
418
393
|
# will convert all pages.
|
419
394
|
# @param read_opts [Hash] Any read options to be passed to ImageMagick
|
420
395
|
# for example: image.format('jpg', page, {density: '300'})
|
421
|
-
# @yield [MiniMagick::Tool
|
396
|
+
# @yield [MiniMagick::Tool] It optionally yields the command,
|
422
397
|
# if you want to add something.
|
423
398
|
# @return [self]
|
424
399
|
#
|
@@ -433,7 +408,7 @@ module MiniMagick
|
|
433
408
|
input_path = path.dup
|
434
409
|
input_path << "[#{page}]" if page && !layer?
|
435
410
|
|
436
|
-
MiniMagick
|
411
|
+
MiniMagick.convert do |convert|
|
437
412
|
read_opts.each do |opt, val|
|
438
413
|
convert.send(opt.to_s, val)
|
439
414
|
end
|
@@ -453,6 +428,9 @@ module MiniMagick
|
|
453
428
|
@info.clear
|
454
429
|
|
455
430
|
self
|
431
|
+
rescue MiniMagick::Invalid, MiniMagick::Error => e
|
432
|
+
new_tempfile.unlink if new_tempfile && @tempfile != new_tempfile
|
433
|
+
raise e
|
456
434
|
end
|
457
435
|
|
458
436
|
##
|
@@ -466,7 +444,7 @@ module MiniMagick
|
|
466
444
|
# c.background "blue"
|
467
445
|
# end
|
468
446
|
#
|
469
|
-
# @yield [MiniMagick::
|
447
|
+
# @yield [MiniMagick::Command]
|
470
448
|
# @see http://www.imagemagick.org/script/mogrify.php
|
471
449
|
# @return [self]
|
472
450
|
#
|
@@ -487,8 +465,11 @@ module MiniMagick
|
|
487
465
|
end
|
488
466
|
end
|
489
467
|
|
490
|
-
|
491
|
-
|
468
|
+
##
|
469
|
+
# Prevents ruby from calling `#to_ary` on the image when checking if it's a
|
470
|
+
# splattable data structure in certain cases.
|
471
|
+
def respond_to_missing?(name, include_all)
|
472
|
+
false
|
492
473
|
end
|
493
474
|
|
494
475
|
##
|
@@ -503,7 +484,7 @@ module MiniMagick
|
|
503
484
|
case output_to
|
504
485
|
when String, Pathname
|
505
486
|
if layer?
|
506
|
-
MiniMagick
|
487
|
+
MiniMagick.convert do |builder|
|
507
488
|
builder << path
|
508
489
|
builder << output_to
|
509
490
|
end
|
@@ -530,7 +511,7 @@ module MiniMagick
|
|
530
511
|
def composite(other_image, output_extension = type.downcase, mask = nil)
|
531
512
|
output_tempfile = MiniMagick::Utilities.tempfile(".#{output_extension}")
|
532
513
|
|
533
|
-
MiniMagick
|
514
|
+
MiniMagick.composite do |composite|
|
534
515
|
yield composite if block_given?
|
535
516
|
composite << other_image.path
|
536
517
|
composite << path
|
@@ -572,27 +553,21 @@ module MiniMagick
|
|
572
553
|
# b.verbose
|
573
554
|
# end # runs `identify -verbose image.jpg`
|
574
555
|
# @return [String] Output from `identify`
|
575
|
-
# @yield [MiniMagick::Tool
|
556
|
+
# @yield [MiniMagick::Tool]
|
576
557
|
#
|
577
558
|
def identify
|
578
|
-
MiniMagick
|
559
|
+
MiniMagick.identify do |builder|
|
579
560
|
yield builder if block_given?
|
580
561
|
builder << path
|
581
562
|
end
|
582
563
|
end
|
583
564
|
|
584
|
-
# @private
|
585
|
-
def run_command(tool_name, *args)
|
586
|
-
MiniMagick::Tool.const_get(tool_name.capitalize).new do |builder|
|
587
|
-
args.each do |arg|
|
588
|
-
builder << arg
|
589
|
-
end
|
590
|
-
end
|
591
|
-
end
|
592
|
-
|
593
565
|
def mogrify(page = nil)
|
594
|
-
MiniMagick
|
566
|
+
MiniMagick.mogrify do |builder|
|
595
567
|
yield builder if block_given?
|
568
|
+
if builder.args.include?("-format")
|
569
|
+
fail MiniMagick::Error, "you must call #format on a MiniMagick::Image directly"
|
570
|
+
end
|
596
571
|
builder << (page ? "#{path}[#{page}]" : path)
|
597
572
|
end
|
598
573
|
|