mini_magick 4.5.1 → 4.6.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.
Potentially problematic release.
This version of mini_magick might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/mini_magick/image.rb +19 -8
- data/lib/mini_magick/image/info.rb +46 -9
- data/lib/mini_magick/tool.rb +15 -0
- data/lib/mini_magick/utilities.rb +1 -1
- data/lib/mini_magick/version.rb +2 -2
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45a32b5c2e6bb0323abe49c1d5c3cb5bd7378f3e
|
4
|
+
data.tar.gz: 430c76ab6de8661491e42bcb21a9ba21d9239e97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a989fdcfa50a2317ce292c04724be10928f01e834c17f6b529646c16ab855be3d2bbcc3d1a929662bf327c7e8e77387a994b42bfa6ad5e159e09237492e9495e
|
7
|
+
data.tar.gz: 4f42cff0e866f24e8bfbd36e2121487424ba7f96a433ddefe3c5edaab70976531bf8bb15ba267eb6ef8d4bf359e752351d74b0416b1a57a2f15e5a84ff3ec1cd
|
data/lib/mini_magick/image.rb
CHANGED
@@ -145,23 +145,22 @@ module MiniMagick
|
|
145
145
|
# is, it gets *modified*. You can either copy it yourself or use {.open}
|
146
146
|
# which creates a temporary file for you and protects your original.
|
147
147
|
#
|
148
|
-
# @param input_path [String] The location of an image file
|
148
|
+
# @param input_path [String, Pathname] The location of an image file
|
149
149
|
# @yield [MiniMagick::Tool::Mogrify] If block is given, {#combine_options}
|
150
150
|
# is called.
|
151
151
|
#
|
152
152
|
def initialize(input_path, tempfile = nil, &block)
|
153
|
-
@path = input_path
|
153
|
+
@path = input_path.to_s
|
154
154
|
@tempfile = tempfile
|
155
155
|
@info = MiniMagick::Image::Info.new(@path)
|
156
156
|
|
157
157
|
combine_options(&block) if block
|
158
158
|
end
|
159
159
|
|
160
|
-
def
|
161
|
-
self.class
|
162
|
-
signature == other.signature
|
160
|
+
def ==(other)
|
161
|
+
self.class == other.class && signature == other.signature
|
163
162
|
end
|
164
|
-
alias
|
163
|
+
alias eql? ==
|
165
164
|
|
166
165
|
def hash
|
167
166
|
signature.hash
|
@@ -269,7 +268,14 @@ module MiniMagick
|
|
269
268
|
#
|
270
269
|
attribute :signature
|
271
270
|
##
|
272
|
-
# Returns the information from `identify -verbose` in a Hash format
|
271
|
+
# Returns the information from `identify -verbose` in a Hash format, for
|
272
|
+
# ImageMagick.
|
273
|
+
#
|
274
|
+
# @return [Hash]
|
275
|
+
attribute :data
|
276
|
+
##
|
277
|
+
# Returns the information from `identify -verbose` in a Hash format, for
|
278
|
+
# GraphicsMagick.
|
273
279
|
#
|
274
280
|
# @return [Hash]
|
275
281
|
attribute :details
|
@@ -331,11 +337,13 @@ module MiniMagick
|
|
331
337
|
# @param page [Integer] If this is an animated gif, say which 'page' you
|
332
338
|
# want with an integer. Default 0 will convert only the first page; 'nil'
|
333
339
|
# will convert all pages.
|
340
|
+
# @param read_opts [Hash] Any read options to be passed to ImageMagick
|
341
|
+
# for example: image.format('jpg', page, {density: '300'})
|
334
342
|
# @yield [MiniMagick::Tool::Convert] It optionally yields the command,
|
335
343
|
# if you want to add something.
|
336
344
|
# @return [self]
|
337
345
|
#
|
338
|
-
def format(format, page = 0)
|
346
|
+
def format(format, page = 0, read_opts={})
|
339
347
|
if @tempfile
|
340
348
|
new_tempfile = MiniMagick::Utilities.tempfile(".#{format}")
|
341
349
|
new_path = new_tempfile.path
|
@@ -347,6 +355,9 @@ module MiniMagick
|
|
347
355
|
input_path << "[#{page}]" if page && !layer?
|
348
356
|
|
349
357
|
MiniMagick::Tool::Convert.new do |convert|
|
358
|
+
read_opts.each do |opt, val|
|
359
|
+
convert.send(opt.to_s, val)
|
360
|
+
end
|
350
361
|
convert << input_path
|
351
362
|
yield convert if block_given?
|
352
363
|
convert << new_path
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "json"
|
2
|
+
|
1
3
|
module MiniMagick
|
2
4
|
class Image
|
3
5
|
# @private
|
@@ -27,6 +29,8 @@ module MiniMagick
|
|
27
29
|
exif
|
28
30
|
when "details"
|
29
31
|
details
|
32
|
+
when "data"
|
33
|
+
data
|
30
34
|
else
|
31
35
|
raw(value)
|
32
36
|
end
|
@@ -80,16 +84,29 @@ module MiniMagick
|
|
80
84
|
|
81
85
|
def exif
|
82
86
|
@info["exif"] ||= (
|
87
|
+
hash = {}
|
83
88
|
output = self["%[EXIF:*]"]
|
84
|
-
pairs = output.gsub(/^exif:/, "").split("\n").map { |line| line.split("=") }
|
85
|
-
Hash[pairs].tap do |hash|
|
86
|
-
ASCII_ENCODED_EXIF_KEYS.each do |key|
|
87
|
-
next unless hash.has_key?(key)
|
88
89
|
|
89
|
-
|
90
|
-
|
90
|
+
output.each_line do |line|
|
91
|
+
line = line.chomp("\n")
|
92
|
+
|
93
|
+
case MiniMagick.cli
|
94
|
+
when :imagemagick
|
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)
|
98
|
+
hash[key] = value
|
99
|
+
else
|
100
|
+
hash[hash.keys.last] << "\n#{line}"
|
101
|
+
end
|
102
|
+
when :graphicsmagick
|
103
|
+
key, value = line.split("=", 2)
|
104
|
+
value.gsub!("\\012", "\n") # convert "\012" characters to newlines
|
105
|
+
hash[key] = value
|
91
106
|
end
|
92
107
|
end
|
108
|
+
|
109
|
+
hash
|
93
110
|
)
|
94
111
|
end
|
95
112
|
|
@@ -102,6 +119,8 @@ module MiniMagick
|
|
102
119
|
end
|
103
120
|
|
104
121
|
def details
|
122
|
+
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?
|
123
|
+
|
105
124
|
@info["details"] ||= (
|
106
125
|
details_string = identify(&:verbose)
|
107
126
|
key_stack = []
|
@@ -132,21 +151,39 @@ module MiniMagick
|
|
132
151
|
)
|
133
152
|
end
|
134
153
|
|
135
|
-
def
|
136
|
-
|
137
|
-
|
154
|
+
def data
|
155
|
+
raise Error, "MiniMagick::Image#data isn't supported on GraphicsMagick. Use MiniMagick::Image#details instead." if MiniMagick.graphicsmagick?
|
156
|
+
|
157
|
+
@info["data"] ||= (
|
158
|
+
json = MiniMagick::Tool::Convert.new do |convert|
|
159
|
+
convert << path
|
160
|
+
convert << "json:"
|
161
|
+
end
|
138
162
|
|
163
|
+
JSON.parse(json).fetch("image")
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
def identify
|
139
168
|
MiniMagick::Tool::Identify.new do |builder|
|
140
169
|
yield builder if block_given?
|
141
170
|
builder << path
|
142
171
|
end
|
143
172
|
end
|
144
173
|
|
174
|
+
private
|
175
|
+
|
145
176
|
def decode_comma_separated_ascii_characters(encoded_value)
|
146
177
|
return encoded_value unless encoded_value.include?(',')
|
147
178
|
encoded_value.scan(/\d+/).map(&:to_i).map(&:chr).join
|
148
179
|
end
|
149
180
|
|
181
|
+
def path
|
182
|
+
value = @path
|
183
|
+
value += "[0]" unless value =~ /\[\d+\]$/
|
184
|
+
value
|
185
|
+
end
|
186
|
+
|
150
187
|
end
|
151
188
|
end
|
152
189
|
end
|
data/lib/mini_magick/tool.rb
CHANGED
@@ -200,6 +200,21 @@ module MiniMagick
|
|
200
200
|
self << "-"
|
201
201
|
end
|
202
202
|
|
203
|
+
##
|
204
|
+
# Adds ImageMagick's pseudo-filename `-` for standard output.
|
205
|
+
#
|
206
|
+
# @example
|
207
|
+
# content = MiniMagick::Tool::Convert.new do |convert|
|
208
|
+
# convert << "input.jpg"
|
209
|
+
# convert.auto_orient
|
210
|
+
# convert.stdout
|
211
|
+
# end
|
212
|
+
# # executes `convert input.jpg -auto-orient -` which returns file contents
|
213
|
+
#
|
214
|
+
def stdout
|
215
|
+
self << "-"
|
216
|
+
end
|
217
|
+
|
203
218
|
##
|
204
219
|
# Define creator operator methods
|
205
220
|
#
|
@@ -14,7 +14,7 @@ module MiniMagick
|
|
14
14
|
#
|
15
15
|
def which(cmd)
|
16
16
|
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
17
|
-
ENV
|
17
|
+
ENV.fetch('PATH').split(File::PATH_SEPARATOR).each do |path|
|
18
18
|
exts.each do |ext|
|
19
19
|
exe = File.join(path, "#{cmd}#{ext}")
|
20
20
|
return exe if File.executable? exe
|
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.6.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: 2016-03
|
16
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rake
|
@@ -117,4 +117,3 @@ signing_key:
|
|
117
117
|
specification_version: 4
|
118
118
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
119
119
|
test_files: []
|
120
|
-
has_rdoc:
|