mini_magick 4.9.3 → 4.11.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 +41 -19
- data/lib/mini_magick/image.rb +63 -7
- data/lib/mini_magick/image/info.rb +12 -2
- data/lib/mini_magick/tool.rb +15 -5
- data/lib/mini_magick/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f97cb0365a2a45cdb41c9091a4339fdd75a37cdb041c454cab800fd9464f5c0f
|
4
|
+
data.tar.gz: b5f97721ee2657631def0e8c498f257639e126a3ad745688356ae5a15ff5de9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5339cf648a6cdc78f5a115e03ab77ec3f61bd83de5fcea0638ccb354e9b03b4c29e59b31e6681da9e1a238b2bee73b2a460ed5db0989eca90c097f29a9b0ebb5
|
7
|
+
data.tar.gz: 53b55f439ac4172e68e82c20e67a357160303fc3c382c0d7bb4bfeb4ba1e3e469b95ff89c517ab15f0c67436ab1c831fee5d7e88d0e981876cbc059b5c7dfad6
|
@@ -4,23 +4,11 @@ require 'logger'
|
|
4
4
|
module MiniMagick
|
5
5
|
module Configuration
|
6
6
|
|
7
|
-
##
|
8
|
-
# Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
|
9
|
-
# [GraphicsMagick](http://www.graphicsmagick.org).
|
10
|
-
#
|
11
|
-
# @return [Symbol] `:imagemagick`, `:imagemagick7`, or `:graphicsmagick`
|
12
|
-
#
|
13
|
-
attr_accessor :cli
|
14
|
-
# @private (for backwards compatibility)
|
15
|
-
attr_accessor :processor
|
16
|
-
|
17
7
|
##
|
18
8
|
# If you don't have the CLI tools in your PATH, you can set the path to the
|
19
9
|
# executables.
|
20
10
|
#
|
21
|
-
|
22
|
-
#
|
23
|
-
attr_accessor :cli_path
|
11
|
+
attr_writer :cli_path
|
24
12
|
# @private (for backwards compatibility)
|
25
13
|
attr_accessor :processor_path
|
26
14
|
|
@@ -43,12 +31,12 @@ module MiniMagick
|
|
43
31
|
#
|
44
32
|
attr_accessor :timeout
|
45
33
|
##
|
46
|
-
# When
|
34
|
+
# When get to `true`, it outputs each command to STDOUT in their shell
|
47
35
|
# version.
|
48
36
|
#
|
49
37
|
# @return [Boolean]
|
50
38
|
#
|
51
|
-
|
39
|
+
attr_reader :debug
|
52
40
|
##
|
53
41
|
# Logger for {#debug}, default is `MiniMagick::Logger.new(STDOUT)`, but
|
54
42
|
# you can override it, for example if you want the logs to be written to
|
@@ -114,17 +102,19 @@ module MiniMagick
|
|
114
102
|
end
|
115
103
|
|
116
104
|
CLI_DETECTION = {
|
105
|
+
imagemagick7: "magick",
|
117
106
|
imagemagick: "mogrify",
|
118
107
|
graphicsmagick: "gm",
|
119
|
-
imagemagick7: "magick",
|
120
108
|
}
|
121
109
|
|
110
|
+
# @private (for backwards compatibility)
|
122
111
|
def processor
|
123
112
|
@processor ||= CLI_DETECTION.values.detect do |processor|
|
124
113
|
MiniMagick::Utilities.which(processor)
|
125
114
|
end
|
126
115
|
end
|
127
116
|
|
117
|
+
# @private (for backwards compatibility)
|
128
118
|
def processor=(processor)
|
129
119
|
@processor = processor.to_s
|
130
120
|
|
@@ -135,11 +125,27 @@ module MiniMagick
|
|
135
125
|
end
|
136
126
|
end
|
137
127
|
|
128
|
+
##
|
129
|
+
# Get [ImageMagick](http://www.imagemagick.org) or
|
130
|
+
# [GraphicsMagick](http://www.graphicsmagick.org).
|
131
|
+
#
|
132
|
+
# @return [Symbol] `:imagemagick` or `:graphicsmagick`
|
133
|
+
#
|
138
134
|
def cli
|
139
|
-
@cli
|
140
|
-
|
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
|
141
143
|
end
|
142
144
|
|
145
|
+
##
|
146
|
+
# Set whether you want to use [ImageMagick](http://www.imagemagick.org) or
|
147
|
+
# [GraphicsMagick](http://www.graphicsmagick.org).
|
148
|
+
#
|
143
149
|
def cli=(value)
|
144
150
|
@cli = value
|
145
151
|
|
@@ -150,10 +156,26 @@ module MiniMagick
|
|
150
156
|
end
|
151
157
|
end
|
152
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
|
+
#
|
153
165
|
def cli_path
|
154
|
-
@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
|
155
173
|
end
|
156
174
|
|
175
|
+
##
|
176
|
+
# When set to `true`, it outputs each command to STDOUT in their shell
|
177
|
+
# version.
|
178
|
+
#
|
157
179
|
def debug=(value)
|
158
180
|
warn "MiniMagick.debug is deprecated and will be removed in MiniMagick 5. Use `MiniMagick.logger.level = Logger::DEBUG` instead."
|
159
181
|
logger.level = value ? Logger::DEBUG : Logger::INFO
|
data/lib/mini_magick/image.rb
CHANGED
@@ -15,7 +15,7 @@ module MiniMagick
|
|
15
15
|
# methods.
|
16
16
|
#
|
17
17
|
# Use this to pass in a stream object. Must respond to #read(size) or be a
|
18
|
-
# binary string object (
|
18
|
+
# binary string object (BLOB)
|
19
19
|
#
|
20
20
|
# Probably easier to use the {.open} method if you want to open a file or a
|
21
21
|
# URL.
|
@@ -82,17 +82,30 @@ module MiniMagick
|
|
82
82
|
def self.open(path_or_url, ext = nil, options = {})
|
83
83
|
options, ext = ext, nil if ext.is_a?(Hash)
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
# Don't use Kernel#open, but reuse its logic
|
86
|
+
openable =
|
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
|
88
93
|
else
|
89
|
-
|
94
|
+
options = { binmode: true }.merge(options)
|
95
|
+
Pathname(path_or_url)
|
90
96
|
end
|
91
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
|
92
103
|
ext.sub!(/:.*/, '') # hack for filenames or URLs that include a colon
|
93
104
|
|
94
|
-
|
95
|
-
read(file, ext)
|
105
|
+
if openable.is_a?(URI::Generic)
|
106
|
+
openable.open(options) { |file| read(file, ext) }
|
107
|
+
else
|
108
|
+
openable.open(**options) { |file| read(file, ext) }
|
96
109
|
end
|
97
110
|
end
|
98
111
|
|
@@ -365,6 +378,23 @@ module MiniMagick
|
|
365
378
|
pixels
|
366
379
|
end
|
367
380
|
|
381
|
+
##
|
382
|
+
# This is used to create image from pixels. This might be required if you
|
383
|
+
# create pixels for some image processing reasons and you want to form
|
384
|
+
# image from those pixels.
|
385
|
+
#
|
386
|
+
# *DANGER*: This operation can be very expensive. Please try to use with
|
387
|
+
# caution.
|
388
|
+
#
|
389
|
+
# @example
|
390
|
+
# # It is given in readme.md file
|
391
|
+
##
|
392
|
+
def self.get_image_from_pixels(pixels, dimension, map, depth, mime_type)
|
393
|
+
pixels = pixels.flatten
|
394
|
+
blob = pixels.pack('C*')
|
395
|
+
import_pixels(blob, *dimension, depth, map, mime_type)
|
396
|
+
end
|
397
|
+
|
368
398
|
##
|
369
399
|
# This is used to change the format of the image. That is, from "tiff to
|
370
400
|
# jpg" or something like that. Once you run it, the instance is pointing to
|
@@ -574,5 +604,31 @@ module MiniMagick
|
|
574
604
|
def layer?
|
575
605
|
path =~ /\[\d+\]$/
|
576
606
|
end
|
607
|
+
|
608
|
+
##
|
609
|
+
# Compares if image width
|
610
|
+
# is greater than height
|
611
|
+
# ============
|
612
|
+
# | |
|
613
|
+
# | |
|
614
|
+
# ============
|
615
|
+
# @return [Boolean]
|
616
|
+
def landscape?
|
617
|
+
width > height
|
618
|
+
end
|
619
|
+
|
620
|
+
##
|
621
|
+
# Compares if image height
|
622
|
+
# is greater than width
|
623
|
+
# ======
|
624
|
+
# | |
|
625
|
+
# | |
|
626
|
+
# | |
|
627
|
+
# | |
|
628
|
+
# ======
|
629
|
+
# @return [Boolean]
|
630
|
+
def portrait?
|
631
|
+
height > width
|
632
|
+
end
|
577
633
|
end
|
578
634
|
end
|
@@ -42,7 +42,7 @@ module MiniMagick
|
|
42
42
|
|
43
43
|
def cheap_info(value)
|
44
44
|
@info.fetch(value) do
|
45
|
-
format, width, height, size = self["%m %w %h %b"].split(" ")
|
45
|
+
format, width, height, size = parse_warnings(self["%m %w %h %b"]).split(" ")
|
46
46
|
|
47
47
|
path = @path
|
48
48
|
path = path.match(/\[\d+\]$/).pre_match if path =~ /\[\d+\]$/
|
@@ -61,6 +61,16 @@ module MiniMagick
|
|
61
61
|
rescue ArgumentError, TypeError
|
62
62
|
raise MiniMagick::Invalid, "image data can't be read"
|
63
63
|
end
|
64
|
+
|
65
|
+
def parse_warnings(raw_info)
|
66
|
+
return raw_info unless raw_info.split("\n").size > 1
|
67
|
+
|
68
|
+
raw_info.split("\n").each do |line|
|
69
|
+
# must match "%m %w %h %b"
|
70
|
+
return line if line.match? /^[A-Z]+ \d+ \d+ \d+B$/
|
71
|
+
end
|
72
|
+
raise TypeError
|
73
|
+
end
|
64
74
|
|
65
75
|
def colorspace
|
66
76
|
@info["colorspace"] ||= self["%r"]
|
@@ -141,7 +151,7 @@ module MiniMagick
|
|
141
151
|
end
|
142
152
|
|
143
153
|
key, _, value = line.partition(/:[\s]/).map(&:strip)
|
144
|
-
hash = key_stack.inject(details_hash) { |
|
154
|
+
hash = key_stack.inject(details_hash) { |_hash, _key| _hash.fetch(_key) }
|
145
155
|
if value.empty?
|
146
156
|
hash[key] = {}
|
147
157
|
key_stack.push key
|
data/lib/mini_magick/tool.rb
CHANGED
@@ -44,8 +44,10 @@ module MiniMagick
|
|
44
44
|
# @private
|
45
45
|
attr_reader :name, :args
|
46
46
|
|
47
|
-
# @param
|
48
|
-
#
|
47
|
+
# @param name [String]
|
48
|
+
# @param options [Hash]
|
49
|
+
# @option options [Boolean] :whiny Whether to raise errors on non-zero
|
50
|
+
# exit codes.
|
49
51
|
# @example
|
50
52
|
# MiniMagick::Tool::Identify.new(whiny: false) do |identify|
|
51
53
|
# identify.help # returns exit status 1, which would otherwise throw an error
|
@@ -190,9 +192,15 @@ module MiniMagick
|
|
190
192
|
# end
|
191
193
|
# # executes `convert wand.gif \( wizard.gif -rotate 30 \) +append images.gif`
|
192
194
|
#
|
193
|
-
def stack
|
195
|
+
def stack(*args)
|
194
196
|
self << "("
|
195
|
-
|
197
|
+
args.each do |value|
|
198
|
+
case value
|
199
|
+
when Hash then value.each { |key, value| send(key, *value) }
|
200
|
+
when String then self << value
|
201
|
+
end
|
202
|
+
end
|
203
|
+
yield self if block_given?
|
196
204
|
self << ")"
|
197
205
|
end
|
198
206
|
|
@@ -227,6 +235,7 @@ module MiniMagick
|
|
227
235
|
##
|
228
236
|
# Define creator operator methods
|
229
237
|
#
|
238
|
+
# @example
|
230
239
|
# mogrify = MiniMagick::Tool.new("mogrify")
|
231
240
|
# mogrify.canvas("khaki")
|
232
241
|
# mogrify.command.join(" ") #=> "mogrify canvas:khaki"
|
@@ -251,10 +260,11 @@ module MiniMagick
|
|
251
260
|
##
|
252
261
|
# Any undefined method will be transformed into a CLI option
|
253
262
|
#
|
263
|
+
# @example
|
254
264
|
# mogrify = MiniMagick::Tool.new("mogrify")
|
255
265
|
# mogrify.adaptive_blur("...")
|
256
266
|
# mogrify.foo_bar
|
257
|
-
# mogrify.command.join(" ") "mogrify -adaptive-blur ... -foo-bar"
|
267
|
+
# mogrify.command.join(" ") # => "mogrify -adaptive-blur ... -foo-bar"
|
258
268
|
#
|
259
269
|
def method_missing(name, *args)
|
260
270
|
option = "-#{name.to_s.tr('_', '-')}"
|
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.
|
4
|
+
version: 4.11.0
|
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:
|
16
|
+
date: 2020-11-06 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rake
|
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
147
|
requirements:
|
148
148
|
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: '0'
|
150
|
+
version: '2.0'
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - ">="
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements:
|
157
157
|
- You must have ImageMagick or GraphicsMagick installed
|
158
|
-
rubygems_version: 3.
|
158
|
+
rubygems_version: 3.1.4
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|