mini_magick 4.6.1 → 4.7.0
Sign up to get free protection for your applications and to get access to all the features.
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 +41 -1
- data/lib/mini_magick/shell.rb +29 -16
- data/lib/mini_magick/version.rb +2 -2
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05cb25170ed225d7cf9cd284fb2ab22c3f420c1e
|
4
|
+
data.tar.gz: cf813a1f5be6b785e3480c75f24af283d30ac5df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf14a742ba8854518d7e5b3b825161ab740244f8d94ce07ce71e5b1793747ba3d650923758eeec2d8ec38bdebc2155c72d5c136ce6475ade7f9fbfe3679130d
|
7
|
+
data.tar.gz: 0141e84fce516b37c6ca2191875fdb28c5c942cad1033d5bf8ce03ed69acca9c26208148639b39ca964139d7f3c2c634d94e10af55316270e669dba39630f08f
|
data/lib/mini_magick/image.rb
CHANGED
@@ -316,6 +316,47 @@ module MiniMagick
|
|
316
316
|
alias pages layers
|
317
317
|
alias frames layers
|
318
318
|
|
319
|
+
##
|
320
|
+
# Returns a matrix of pixels from the image. The matrix is constructed as
|
321
|
+
# an array (1) of arrays (2) of arrays (3) of unsigned integers:
|
322
|
+
#
|
323
|
+
# 1) one for each row of pixels
|
324
|
+
# 2) one for each column of pixels
|
325
|
+
# 3) three elements in the range 0-255, one for each of the RGB color channels
|
326
|
+
#
|
327
|
+
# @example
|
328
|
+
# img = MiniMagick::Image.open 'image.jpg'
|
329
|
+
# pixels = img.get_pixels
|
330
|
+
# pixels[3][2][1] # the green channel value from the 4th-row, 3rd-column pixel
|
331
|
+
#
|
332
|
+
# It can also be called after applying transformations:
|
333
|
+
#
|
334
|
+
# @example
|
335
|
+
# img = MiniMagick::Image.open 'image.jpg'
|
336
|
+
# img.crop '20x30+10+5'
|
337
|
+
# img.colorspace 'Gray'
|
338
|
+
# pixels = img.get_pixels
|
339
|
+
#
|
340
|
+
# In this example, all pixels in pix should now have equal R, G, and B values.
|
341
|
+
#
|
342
|
+
# @return [Array] Matrix of each color of each pixel
|
343
|
+
def get_pixels
|
344
|
+
output = MiniMagick::Tool::Convert.new do |convert|
|
345
|
+
convert << path
|
346
|
+
convert.depth(8)
|
347
|
+
convert << "RGB:-"
|
348
|
+
end
|
349
|
+
|
350
|
+
pixels_array = output.unpack("C*")
|
351
|
+
pixels = pixels_array.each_slice(3).each_slice(width).to_a
|
352
|
+
|
353
|
+
# deallocate large intermediary objects
|
354
|
+
output.clear
|
355
|
+
pixels_array.clear
|
356
|
+
|
357
|
+
pixels
|
358
|
+
end
|
359
|
+
|
319
360
|
##
|
320
361
|
# This is used to change the format of the image. That is, from "tiff to
|
321
362
|
# jpg" or something like that. Once you run it, the instance is pointing to
|
@@ -531,6 +572,5 @@ module MiniMagick
|
|
531
572
|
def layer?
|
532
573
|
path =~ /\[\d+\]$/
|
533
574
|
end
|
534
|
-
|
535
575
|
end
|
536
576
|
end
|
data/lib/mini_magick/shell.rb
CHANGED
@@ -13,12 +13,9 @@ module MiniMagick
|
|
13
13
|
def run(command, options = {})
|
14
14
|
stdout, stderr, status = execute(command, stdin: options[:stdin])
|
15
15
|
|
16
|
-
|
17
|
-
when 1
|
16
|
+
if status != 0 && options.fetch(:whiny, MiniMagick.whiny)
|
18
17
|
fail MiniMagick::Error, "`#{command.join(" ")}` failed with error:\n#{stderr}"
|
19
|
-
|
20
|
-
fail MiniMagick::Error, stderr
|
21
|
-
end if options.fetch(:whiny, MiniMagick.whiny)
|
18
|
+
end
|
22
19
|
|
23
20
|
$stderr.print(stderr) unless options[:stderr] == false
|
24
21
|
|
@@ -28,9 +25,7 @@ module MiniMagick
|
|
28
25
|
def execute(command, options = {})
|
29
26
|
stdout, stderr, status =
|
30
27
|
log(command.join(" ")) do
|
31
|
-
|
32
|
-
send("execute_#{MiniMagick.shell_api.gsub("-", "_")}", command, options)
|
33
|
-
end
|
28
|
+
send("execute_#{MiniMagick.shell_api.gsub("-", "_")}", command, options)
|
34
29
|
end
|
35
30
|
|
36
31
|
[stdout, stderr, status.exitstatus]
|
@@ -43,20 +38,38 @@ module MiniMagick
|
|
43
38
|
def execute_open3(command, options = {})
|
44
39
|
require "open3"
|
45
40
|
|
46
|
-
|
41
|
+
in_w, out_r, err_r, subprocess_thread = Open3.popen3(*command)
|
42
|
+
|
43
|
+
capture_command(in_w, out_r, err_r, subprocess_thread, options)
|
47
44
|
end
|
48
45
|
|
49
46
|
def execute_posix_spawn(command, options = {})
|
50
47
|
require "posix-spawn"
|
51
48
|
|
52
|
-
pid,
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
pid, in_w, out_r, err_r = POSIX::Spawn.popen4(*command)
|
50
|
+
subprocess_thread = Process.detach(pid)
|
51
|
+
|
52
|
+
capture_command(in_w, out_r, err_r, subprocess_thread, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def capture_command(in_w, out_r, err_r, subprocess_thread, options)
|
56
|
+
[in_w, out_r, err_r].each(&:binmode)
|
57
|
+
stdout_reader = Thread.new { out_r.read }
|
58
|
+
stderr_reader = Thread.new { err_r.read }
|
59
|
+
begin
|
60
|
+
in_w.write options[:stdin].to_s
|
61
|
+
rescue Errno::EPIPE
|
62
|
+
end
|
63
|
+
in_w.close
|
64
|
+
|
65
|
+
Timeout.timeout(MiniMagick.timeout) { subprocess_thread.join }
|
58
66
|
|
59
|
-
[
|
67
|
+
[stdout_reader.value, stderr_reader.value, subprocess_thread.value]
|
68
|
+
rescue Timeout::Error => error
|
69
|
+
Process.kill("TERM", subprocess_thread.pid)
|
70
|
+
raise error
|
71
|
+
ensure
|
72
|
+
[out_r, err_r].each(&:close)
|
60
73
|
end
|
61
74
|
|
62
75
|
def log(command, &block)
|
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.7.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: 2017-
|
16
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rake
|
@@ -43,6 +43,34 @@ dependencies:
|
|
43
43
|
- - "~>"
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 3.5.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard
|
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'
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: guard-rspec
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
46
74
|
- !ruby/object:Gem::Dependency
|
47
75
|
name: posix-spawn
|
48
76
|
requirement: !ruby/object:Gem::Requirement
|