mini_magick 4.0.0 → 4.1.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_gmagick.rb +1 -1
- data/lib/mini_magick/configuration.rb +22 -0
- data/lib/mini_magick/image.rb +9 -5
- data/lib/mini_magick/shell.rb +17 -4
- data/lib/mini_magick/tool.rb +33 -10
- data/lib/mini_magick/version.rb +1 -1
- metadata +19 -30
- data/spec/fixtures/animation.gif +0 -0
- data/spec/fixtures/default.jpg +0 -0
- data/spec/fixtures/exif.jpg +0 -0
- data/spec/fixtures/image.psd +0 -0
- data/spec/fixtures/not_an_image.rb +0 -1
- data/spec/lib/mini_magick/configuration_spec.rb +0 -66
- data/spec/lib/mini_magick/image_spec.rb +0 -460
- data/spec/lib/mini_magick/shell_spec.rb +0 -66
- data/spec/lib/mini_magick/tool_spec.rb +0 -107
- data/spec/lib/mini_magick/utilities_spec.rb +0 -17
- data/spec/lib/mini_magick_spec.rb +0 -39
- data/spec/spec_helper.rb +0 -21
- data/spec/support/helpers.rb +0 -37
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8921e089d8d63d1391e76876bc63b4e3ff953706
|
|
4
|
+
data.tar.gz: 38930195578ded9545d86b4225718671a9cd8b6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39cc0fccd098a964a02be8e2cde7565d492ab9a5831df89a2f1b90d751d67368c13584c05ef3253aab51f8aecf107a52ca489a6849bd32e80a334869500f4628
|
|
7
|
+
data.tar.gz: 9c620a81d8b8e601a172d3b8333f4020048e2b7d385ce40fe85caff7f6df7480f1e08c8046d8fa10d66164eb264efe06d9303f111444f55c6193546ca34ab0f2
|
data/lib/mini_gmagick.rb
CHANGED
|
@@ -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
|
|
@@ -63,9 +64,28 @@ module MiniMagick
|
|
|
63
64
|
#
|
|
64
65
|
attr_accessor :validate_on_write
|
|
65
66
|
|
|
67
|
+
##
|
|
68
|
+
# If set to `false`, it will not raise errors when ImageMagick returns
|
|
69
|
+
# status code different than 0. Defaults to `true`.
|
|
70
|
+
#
|
|
71
|
+
# @return [Boolean]
|
|
72
|
+
#
|
|
73
|
+
attr_accessor :whiny
|
|
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
|
+
|
|
66
84
|
def self.extended(base)
|
|
67
85
|
base.validate_on_create = true
|
|
68
86
|
base.validate_on_write = true
|
|
87
|
+
base.whiny = true
|
|
88
|
+
base.shell_api = "open3"
|
|
69
89
|
end
|
|
70
90
|
|
|
71
91
|
##
|
|
@@ -103,6 +123,8 @@ module MiniMagick
|
|
|
103
123
|
case processor.to_s
|
|
104
124
|
when "mogrify" then :imagemagick
|
|
105
125
|
when "gm" then :graphicsmagick
|
|
126
|
+
else
|
|
127
|
+
raise MiniMagick::Error, "ImageMagick/GraphicsMagick is not installed"
|
|
106
128
|
end
|
|
107
129
|
end
|
|
108
130
|
|
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|
|
|
@@ -121,7 +121,11 @@ module MiniMagick
|
|
|
121
121
|
#
|
|
122
122
|
def self.attribute(name, key = name.to_s)
|
|
123
123
|
define_method(name) do |*args|
|
|
124
|
-
|
|
124
|
+
if args.any? && MiniMagick::Tool::Mogrify.instance_methods.include?(name)
|
|
125
|
+
mogrify { |b| b.send(name, *args) }
|
|
126
|
+
else
|
|
127
|
+
@info[key, *args]
|
|
128
|
+
end
|
|
125
129
|
end
|
|
126
130
|
end
|
|
127
131
|
|
|
@@ -401,7 +405,7 @@ module MiniMagick
|
|
|
401
405
|
builder << output_to
|
|
402
406
|
end
|
|
403
407
|
else
|
|
404
|
-
FileUtils.copy_file path, output_to
|
|
408
|
+
FileUtils.copy_file path, output_to unless path == output_to.to_s
|
|
405
409
|
end
|
|
406
410
|
else
|
|
407
411
|
IO.copy_stream File.open(path, "rb"), output_to
|
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
|
@@ -65,7 +65,7 @@ module MiniMagick
|
|
|
65
65
|
# MiniMagick::Tool::Identify.new(false) do |identify|
|
|
66
66
|
# identify.help # returns exit status 1, which would otherwise throw an error
|
|
67
67
|
# end
|
|
68
|
-
def initialize(name, whiny =
|
|
68
|
+
def initialize(name, whiny = MiniMagick.whiny)
|
|
69
69
|
@name = name
|
|
70
70
|
@whiny = whiny
|
|
71
71
|
@args = []
|
|
@@ -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.
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Corey Johnson
|
|
@@ -12,7 +12,7 @@ authors:
|
|
|
12
12
|
autorequire:
|
|
13
13
|
bindir: bin
|
|
14
14
|
cert_chain: []
|
|
15
|
-
date:
|
|
15
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: rake
|
|
@@ -42,6 +42,20 @@ dependencies:
|
|
|
42
42
|
- - "~>"
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
44
|
version: 3.1.0
|
|
45
|
+
- !ruby/object:Gem::Dependency
|
|
46
|
+
name: posix-spawn
|
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
type: :development
|
|
53
|
+
prerelease: false
|
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
45
59
|
description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
|
46
60
|
email:
|
|
47
61
|
- probablycorey@gmail.com
|
|
@@ -76,19 +90,6 @@ files:
|
|
|
76
90
|
- lib/mini_magick/tool/stream.rb
|
|
77
91
|
- lib/mini_magick/utilities.rb
|
|
78
92
|
- lib/mini_magick/version.rb
|
|
79
|
-
- spec/fixtures/animation.gif
|
|
80
|
-
- spec/fixtures/default.jpg
|
|
81
|
-
- spec/fixtures/exif.jpg
|
|
82
|
-
- spec/fixtures/image.psd
|
|
83
|
-
- spec/fixtures/not_an_image.rb
|
|
84
|
-
- spec/lib/mini_magick/configuration_spec.rb
|
|
85
|
-
- spec/lib/mini_magick/image_spec.rb
|
|
86
|
-
- spec/lib/mini_magick/shell_spec.rb
|
|
87
|
-
- spec/lib/mini_magick/tool_spec.rb
|
|
88
|
-
- spec/lib/mini_magick/utilities_spec.rb
|
|
89
|
-
- spec/lib/mini_magick_spec.rb
|
|
90
|
-
- spec/spec_helper.rb
|
|
91
|
-
- spec/support/helpers.rb
|
|
92
93
|
homepage: https://github.com/minimagick/minimagick
|
|
93
94
|
licenses:
|
|
94
95
|
- MIT
|
|
@@ -110,21 +111,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
111
|
requirements:
|
|
111
112
|
- You must have ImageMagick or GraphicsMagick installed
|
|
112
113
|
rubyforge_project:
|
|
113
|
-
rubygems_version: 2.
|
|
114
|
+
rubygems_version: 2.4.5
|
|
114
115
|
signing_key:
|
|
115
116
|
specification_version: 4
|
|
116
117
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
|
117
|
-
test_files:
|
|
118
|
-
|
|
119
|
-
- spec/fixtures/default.jpg
|
|
120
|
-
- spec/fixtures/exif.jpg
|
|
121
|
-
- spec/fixtures/image.psd
|
|
122
|
-
- spec/fixtures/not_an_image.rb
|
|
123
|
-
- spec/lib/mini_magick/configuration_spec.rb
|
|
124
|
-
- spec/lib/mini_magick/image_spec.rb
|
|
125
|
-
- spec/lib/mini_magick/shell_spec.rb
|
|
126
|
-
- spec/lib/mini_magick/tool_spec.rb
|
|
127
|
-
- spec/lib/mini_magick/utilities_spec.rb
|
|
128
|
-
- spec/lib/mini_magick_spec.rb
|
|
129
|
-
- spec/spec_helper.rb
|
|
130
|
-
- spec/support/helpers.rb
|
|
118
|
+
test_files: []
|
|
119
|
+
has_rdoc:
|
data/spec/fixtures/animation.gif
DELETED
|
Binary file
|
data/spec/fixtures/default.jpg
DELETED
|
Binary file
|
data/spec/fixtures/exif.jpg
DELETED
|
Binary file
|
data/spec/fixtures/image.psd
DELETED
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
expect(__FILE__).not_to be_an_image
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe MiniMagick::Configuration do
|
|
4
|
-
subject { Object.new.extend(MiniMagick::Configuration) }
|
|
5
|
-
|
|
6
|
-
describe "#configure" do
|
|
7
|
-
it "yields self" do
|
|
8
|
-
expect { |b| subject.configure(&b) }
|
|
9
|
-
.to yield_with_args(subject)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "#cli" do
|
|
14
|
-
it "can be assigned" do
|
|
15
|
-
subject.cli = :imagemagick
|
|
16
|
-
expect(subject.cli).to eq :imagemagick
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "returns :imagemagick if #processor is mogrify" do
|
|
20
|
-
allow(subject).to receive(:processor).and_return("mogrify")
|
|
21
|
-
expect(subject.cli).to eq :imagemagick
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "returns :graphicsmagick if #processor is gm" do
|
|
25
|
-
allow(subject).to receive(:processor).and_return("gm")
|
|
26
|
-
expect(subject.cli).to eq :graphicsmagick
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "returns nil of #processor is nil" do
|
|
30
|
-
allow(subject).to receive(:processor).and_return(nil)
|
|
31
|
-
expect(subject.cli).to eq nil
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "#cli=" do
|
|
36
|
-
it "raises an error when set to an invalid value" do
|
|
37
|
-
expect { subject.cli = :grapicsmagick }
|
|
38
|
-
.to raise_error(ArgumentError)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe "#processor" do
|
|
43
|
-
it "assigns :mogrify by default" do
|
|
44
|
-
expect(subject.processor).to eq "mogrify"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "assigns :gm if ImageMagick is not available" do
|
|
48
|
-
allow(MiniMagick::Utilities).to receive(:which).with("mogrify").and_return(nil)
|
|
49
|
-
allow(MiniMagick::Utilities).to receive(:which).with("gm").and_return(true)
|
|
50
|
-
expect(subject.processor).to eq "gm"
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "returns nil if neither ImageMagick nor GraphicsMagick are available" do
|
|
54
|
-
allow(MiniMagick::Utilities).to receive(:which).with("mogrify").and_return(nil)
|
|
55
|
-
allow(MiniMagick::Utilities).to receive(:which).with("gm").and_return(nil)
|
|
56
|
-
expect(subject.processor).to eq nil
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe "#processor=" do
|
|
61
|
-
it "raises an error when set to an invalid value" do
|
|
62
|
-
expect { subject.processor = "mogrfy" }
|
|
63
|
-
.to raise_error(ArgumentError)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,460 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "pathname"
|
|
3
|
-
require "tempfile"
|
|
4
|
-
require "fileutils"
|
|
5
|
-
require "stringio"
|
|
6
|
-
|
|
7
|
-
["ImageMagick", "GraphicsMagick"].each do |cli|
|
|
8
|
-
RSpec.context "With #{cli}", cli: cli.downcase.to_sym do
|
|
9
|
-
describe MiniMagick::Image do
|
|
10
|
-
subject { described_class.open(image_path) }
|
|
11
|
-
|
|
12
|
-
describe ".read" do
|
|
13
|
-
it "reads image from String" do
|
|
14
|
-
string = File.binread(image_path)
|
|
15
|
-
image = described_class.read(string)
|
|
16
|
-
expect(image).to be_valid
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "reads image from StringIO" do
|
|
20
|
-
stringio = StringIO.new(File.binread(image_path))
|
|
21
|
-
image = described_class.read(stringio)
|
|
22
|
-
expect(image).to be_valid
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "reads image from tempfile" do
|
|
26
|
-
tempfile = Tempfile.open('magick')
|
|
27
|
-
FileUtils.cp image_path, tempfile.path
|
|
28
|
-
image = described_class.read(tempfile)
|
|
29
|
-
expect(image).to be_valid
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe ".import_pixels" do
|
|
34
|
-
let(:dimensions) { [325, 200] }
|
|
35
|
-
let(:depth) { 16 } # 16 bits (2 bytes) per pixel
|
|
36
|
-
let(:map) { 'gray' }
|
|
37
|
-
let(:pixels) { Array.new(dimensions.inject(:*)) { |i| i } }
|
|
38
|
-
let(:blob) { pixels.pack('S*') } # unsigned short, native byte order
|
|
39
|
-
|
|
40
|
-
it "can import pixels with default format" do
|
|
41
|
-
image = described_class.import_pixels(blob, *dimensions, depth, map)
|
|
42
|
-
|
|
43
|
-
expect(image).to be_valid
|
|
44
|
-
expect(image.type).to eq 'PNG'
|
|
45
|
-
expect(image.dimensions).to eq dimensions
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "can import pixels with custom format" do
|
|
49
|
-
image = described_class.import_pixels(blob, *dimensions, depth, map, 'jpeg')
|
|
50
|
-
|
|
51
|
-
expect(image).to be_valid
|
|
52
|
-
expect(image.type).to eq 'JPEG'
|
|
53
|
-
expect(image.dimensions).to eq dimensions
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe ".open" do
|
|
58
|
-
it "makes a copy of the image" do
|
|
59
|
-
image = described_class.open(image_path)
|
|
60
|
-
expect(image.path).not_to eq image_path
|
|
61
|
-
expect(image).to be_valid
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "accepts a Pathname" do
|
|
65
|
-
image = described_class.open(Pathname(image_path))
|
|
66
|
-
expect(image).to be_valid
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "loads a remote image" do
|
|
70
|
-
begin
|
|
71
|
-
image = described_class.open(image_url)
|
|
72
|
-
expect(image).to be_valid
|
|
73
|
-
rescue SocketError
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "validates the image" do
|
|
78
|
-
expect { described_class.open(image_path(:not)) }
|
|
79
|
-
.to raise_error(MiniMagick::Invalid)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
describe ".create" do
|
|
84
|
-
def create(path = image_path)
|
|
85
|
-
described_class.create do |f|
|
|
86
|
-
f.write(File.binread(path))
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "creates an image" do
|
|
91
|
-
image = create
|
|
92
|
-
expect(File.exists?(image.path)).to eq true
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it "validates the image if validation is set" do
|
|
96
|
-
allow(MiniMagick).to receive(:validate_on_create).and_return(true)
|
|
97
|
-
expect { create(image_path(:not)) }
|
|
98
|
-
.to raise_error(MiniMagick::Invalid)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it "doesn't validate image if validation is disabled" do
|
|
102
|
-
allow(MiniMagick).to receive(:validate_on_create).and_return(false)
|
|
103
|
-
expect { create(image_path(:not)) }
|
|
104
|
-
.not_to raise_error
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
describe "#initialize" do
|
|
109
|
-
it "initializes a new image" do
|
|
110
|
-
image = described_class.new(image_path)
|
|
111
|
-
expect(image).to be_valid
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "accepts a block which it passes on to #combine_options" do
|
|
115
|
-
image = described_class.new(subject.path) do |b|
|
|
116
|
-
b.resize "100x100!"
|
|
117
|
-
end
|
|
118
|
-
expect(image.dimensions).to eq [100, 100]
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
describe "equivalence" do
|
|
123
|
-
subject(:image) { described_class.new(image_path) }
|
|
124
|
-
let(:same_image) { described_class.new(image_path) }
|
|
125
|
-
let(:other_image) { described_class.new(image_path(:exif)) }
|
|
126
|
-
|
|
127
|
-
it "is #== and #eql? to itself" do
|
|
128
|
-
expect(image).to eq(image)
|
|
129
|
-
expect(image).to eql(image)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "is #== and #eql? to an instance of the same image" do
|
|
133
|
-
expect(image).to eq(same_image)
|
|
134
|
-
expect(image).to eql(same_image)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "is not #== nor #eql? to an instance of a different image" do
|
|
138
|
-
expect(image).not_to eq(other_image)
|
|
139
|
-
expect(image).not_to eql(other_image)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "generates the same hash code for an instance of the same image" do
|
|
143
|
-
expect(image.hash).to eq(same_image.hash)
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
it "generates different same hash codes for a different image" do
|
|
147
|
-
expect(image.hash).not_to eq(other_image.hash)
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe "#format" do
|
|
152
|
-
subject { described_class.open(image_path(:jpg)) }
|
|
153
|
-
|
|
154
|
-
it "changes the format of the photo" do
|
|
155
|
-
expect { subject.format("png") }
|
|
156
|
-
.to change { subject.type }
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "reformats an image with a given extension" do
|
|
160
|
-
expect { subject.format('png') }
|
|
161
|
-
.to change { File.extname(subject.path) }.to ".png"
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "creates the file with new extension" do
|
|
165
|
-
subject.format('png')
|
|
166
|
-
expect(File.exist?(subject.path)).to eq true
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it "accepts a block of additional commands" do
|
|
170
|
-
expect {
|
|
171
|
-
subject.format("png") do |b|
|
|
172
|
-
b.resize("100x100!")
|
|
173
|
-
end
|
|
174
|
-
}.to change { subject.dimensions }.to [100, 100]
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
it "works without an extension" do
|
|
178
|
-
subject = described_class.open(image_path(:without_extension))
|
|
179
|
-
expect { subject.format("png") }
|
|
180
|
-
.to change { File.extname(subject.path) }.from("").to(".png")
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it "deletes the previous tempfile" do
|
|
184
|
-
old_path = subject.path.dup
|
|
185
|
-
subject.format('png')
|
|
186
|
-
expect(File.exist?(old_path)).to eq false
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
it "doesn't delete itself when formatted to the same format" do
|
|
190
|
-
subject.format(subject.type.downcase)
|
|
191
|
-
expect(File.exists?(subject.path)).to eq true
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
it "reformats multi-image formats to multiple images" do
|
|
195
|
-
subject = described_class.open(image_path(:animation))
|
|
196
|
-
subject.format('jpg', nil)
|
|
197
|
-
expect(Dir[subject.path.sub('.', '*.')]).not_to be_empty
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it "reformats multi-image formats to a single image" do
|
|
201
|
-
subject = described_class.open(image_path(:animation))
|
|
202
|
-
subject.format('jpg')
|
|
203
|
-
expect(subject).to be_valid
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
it "returns self" do
|
|
207
|
-
expect(subject.format('png')).to eq subject
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
describe "#write" do
|
|
212
|
-
it "writes the image" do
|
|
213
|
-
output_path = random_path("test output")
|
|
214
|
-
subject.write(output_path)
|
|
215
|
-
expect(described_class.new(output_path)).to be_valid
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it "writes an image with stream" do
|
|
219
|
-
output_stream = StringIO.new
|
|
220
|
-
subject.write(output_stream)
|
|
221
|
-
expect(described_class.read(output_stream.string)).to be_valid
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
it "writes layers" do
|
|
225
|
-
output_path = random_path(["", ".#{subject.type.downcase}"])
|
|
226
|
-
subject = described_class.new(image_path(:gif))
|
|
227
|
-
subject.frames.first.write(output_path)
|
|
228
|
-
expect(described_class.new(output_path)).to be_valid
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
it "accepts a Pathname" do
|
|
232
|
-
output_path = Pathname(random_path)
|
|
233
|
-
subject.write(output_path)
|
|
234
|
-
expect(described_class.new(output_path.to_s)).to be_valid
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
describe "#valid?" do
|
|
239
|
-
it "returns true when image is valid" do
|
|
240
|
-
image = described_class.new(image_path)
|
|
241
|
-
expect(image).to be_valid
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
it "returns false when image is not valid" do
|
|
245
|
-
image = described_class.new(image_path(:not))
|
|
246
|
-
expect(image).not_to be_valid
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
describe "#[]" do
|
|
251
|
-
it "inspects image meta info" do
|
|
252
|
-
expect(subject[:width]).to be_a(Fixnum)
|
|
253
|
-
expect(subject[:height]).to be_a(Fixnum)
|
|
254
|
-
expect(subject[:dimensions]).to all(be_a(Fixnum))
|
|
255
|
-
expect(subject[:colorspace]).to be_a(String)
|
|
256
|
-
expect(subject[:format]).to match(/[A-Z]/)
|
|
257
|
-
expect(subject[:signature]).to match(/[[:alnum:]]{64}/)
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
it "supports string keys" do
|
|
261
|
-
expect(subject["width"]).to be_a(Fixnum)
|
|
262
|
-
expect(subject["height"]).to be_a(Fixnum)
|
|
263
|
-
expect(subject["dimensions"]).to all(be_a(Fixnum))
|
|
264
|
-
expect(subject["colorspace"]).to be_a(String)
|
|
265
|
-
expect(subject["format"]).to match(/[A-Z]/)
|
|
266
|
-
expect(subject['signature']).to match(/[[:alnum:]]{64}/)
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
it "reads exif" do
|
|
270
|
-
subject = described_class.new(image_path(:exif))
|
|
271
|
-
gps_latitude = subject.exif["GPSLatitude"].split(/\s*,\s*/)
|
|
272
|
-
gps_longitude = subject.exif["GPSLongitude"].split(/\s*,\s*/)
|
|
273
|
-
|
|
274
|
-
expect(subject["EXIF:ColorSpace"]).to eq "1"
|
|
275
|
-
expect(gps_latitude.size).to eq 3
|
|
276
|
-
expect(gps_longitude.size).to eq 3
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
it "passes unknown values directly to -format" do
|
|
280
|
-
expect(subject["%w %h"].split.map(&:to_i)).to eq [subject[:width], subject[:height]]
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
it "has attributes" do
|
|
285
|
-
expect(subject.type).to match(/^[A-Z]+$/)
|
|
286
|
-
expect(subject.mime_type).to match(/^image\/[a-z]+$/)
|
|
287
|
-
expect(subject.width).to be_a(Fixnum).and be_nonzero
|
|
288
|
-
expect(subject.height).to be_a(Fixnum).and be_nonzero
|
|
289
|
-
expect(subject.dimensions).to all(be_a(Fixnum))
|
|
290
|
-
expect(subject.size).to be_a(Fixnum).and be_nonzero
|
|
291
|
-
expect(subject.colorspace).to be_a(String)
|
|
292
|
-
expect(subject.resolution).to all(be_a(Fixnum))
|
|
293
|
-
expect(subject.signature).to match(/[[:alnum:]]{64}/)
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
describe "#exif" do
|
|
297
|
-
subject { described_class.new(image_path(:exif)) }
|
|
298
|
-
|
|
299
|
-
it "returns a hash of EXIF data" do
|
|
300
|
-
expect(subject.exif["DateTimeOriginal"]).to be_a(String)
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
it "decodes the ExifVersion" do
|
|
304
|
-
expect(subject.exif["ExifVersion"]).to eq("0221")
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
describe "#resolution" do
|
|
309
|
-
it "accepts units", skip_cli: :graphicsmagick do
|
|
310
|
-
expect(subject.resolution("PixelsPerCentimeter"))
|
|
311
|
-
.not_to eq subject.resolution("PixelsPerInch")
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
describe "#mime_type" do
|
|
316
|
-
it "returns the correct mime type" do
|
|
317
|
-
jpg = described_class.new(image_path(:jpg))
|
|
318
|
-
expect(jpg.mime_type).to eq 'image/jpeg'
|
|
319
|
-
end
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
describe "#layers" do
|
|
323
|
-
it "returns a list of images" do
|
|
324
|
-
expect(subject.layers).to all(be_a(MiniMagick::Image))
|
|
325
|
-
expect(subject.layers.first).to be_valid
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
it "returns multiple images for GIFs, PDFs and PSDs" do
|
|
329
|
-
gif = described_class.new(image_path(:gif))
|
|
330
|
-
psd = described_class.new(image_path(:psd))
|
|
331
|
-
|
|
332
|
-
expect(gif.frames.count).to be > 1
|
|
333
|
-
expect(psd.layers.count).to be > 1 unless MiniMagick.graphicsmagick?
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
it "returns one image for other formats" do
|
|
337
|
-
jpg = described_class.new(image_path(:jpg))
|
|
338
|
-
|
|
339
|
-
expect(jpg.layers.count).to eq 1
|
|
340
|
-
end
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
describe "missing methods" do
|
|
344
|
-
context "for a known method" do
|
|
345
|
-
it "is executed by #method_missing" do
|
|
346
|
-
expect { subject.resize '20x30!' }
|
|
347
|
-
.to change { subject.dimensions }.to [20, 30]
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
it "returns self" do
|
|
351
|
-
expect(subject.resize('20x30!')).to eq subject
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
it "can be responed to" do
|
|
355
|
-
expect(subject.respond_to?(:resize)).to eq true
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
context "for an unknown method" do
|
|
360
|
-
it "fails with a NoMethodError" do
|
|
361
|
-
expect { subject.foo }
|
|
362
|
-
.to raise_error(NoMethodError, /MiniMagick::Image/)
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
it "cannot be responded to" do
|
|
366
|
-
expect(subject.respond_to?(:foo)).to eq false
|
|
367
|
-
end
|
|
368
|
-
end
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
describe "#combine_options" do
|
|
372
|
-
it "chains multiple options and executes them in one command" do
|
|
373
|
-
expect {
|
|
374
|
-
subject.combine_options { |c| c.resize '20x30!' }
|
|
375
|
-
}.to change { subject.dimensions }.to [20, 30]
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
it "doesn't allow calling of #format" do
|
|
379
|
-
expect { subject.combine_options { |c| c.format("png") } }
|
|
380
|
-
.to raise_error(NoMethodError)
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
it "returns self" do
|
|
384
|
-
expect(subject.combine_options {}).to eq subject
|
|
385
|
-
end
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
describe "#composite" do
|
|
389
|
-
let(:other_image) { described_class.open(image_path) }
|
|
390
|
-
let(:mask) { described_class.open(image_path) }
|
|
391
|
-
|
|
392
|
-
it "creates a composite of two images" do
|
|
393
|
-
image = subject.composite(other_image)
|
|
394
|
-
expect(image).to be_valid
|
|
395
|
-
end
|
|
396
|
-
|
|
397
|
-
it "creates a composite of two images with mask" do
|
|
398
|
-
image = subject.composite(other_image, 'jpg', mask)
|
|
399
|
-
expect(image).to be_valid
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
it "yields an optional block" do
|
|
403
|
-
expect { |b| subject.composite(other_image, &b) }
|
|
404
|
-
.to yield_with_args(an_instance_of(MiniMagick::Tool::Composite))
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
it "makes the composited image with the provided extension" do
|
|
408
|
-
result = subject.composite(other_image, 'png')
|
|
409
|
-
expect(result.path).to end_with ".png"
|
|
410
|
-
|
|
411
|
-
result = subject.composite(other_image)
|
|
412
|
-
expect(result.path).to end_with ".jpg"
|
|
413
|
-
end
|
|
414
|
-
end
|
|
415
|
-
|
|
416
|
-
describe "#collapse!" do
|
|
417
|
-
subject { described_class.open(image_path(:animation)) }
|
|
418
|
-
|
|
419
|
-
it "collapses the image to one frame" do
|
|
420
|
-
subject.collapse!
|
|
421
|
-
expect(subject.identify.lines.count).to eq 1
|
|
422
|
-
end
|
|
423
|
-
|
|
424
|
-
it "keeps the extension" do
|
|
425
|
-
expect { subject.collapse! }
|
|
426
|
-
.not_to change { subject.type }
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
it "clears the info" do
|
|
430
|
-
expect { subject.collapse! }
|
|
431
|
-
.to change { subject.size }
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
it "returns self" do
|
|
435
|
-
expect(subject.collapse!).to eq subject
|
|
436
|
-
end
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
describe "#identify" do
|
|
440
|
-
it "returns the output of identify" do
|
|
441
|
-
expect(subject.identify).to match(subject.type)
|
|
442
|
-
end
|
|
443
|
-
|
|
444
|
-
it "yields an optional block" do
|
|
445
|
-
output = subject.identify do |b|
|
|
446
|
-
b.verbose
|
|
447
|
-
end
|
|
448
|
-
expect(output).to match("Format:")
|
|
449
|
-
end
|
|
450
|
-
end
|
|
451
|
-
|
|
452
|
-
describe "#run_command" do
|
|
453
|
-
it "runs the given command" do
|
|
454
|
-
output = subject.run_command("identify", "-format", "%w", subject.path)
|
|
455
|
-
expect(output).to eq subject.width.to_s
|
|
456
|
-
end
|
|
457
|
-
end
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
end
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe MiniMagick::Shell do
|
|
4
|
-
subject { described_class.new }
|
|
5
|
-
|
|
6
|
-
describe "#run" do
|
|
7
|
-
it "calls #execute with the command" do
|
|
8
|
-
expect(subject).to receive(:execute).and_call_original
|
|
9
|
-
subject.run(%W[identify #{image_path}])
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "returns stdout" do
|
|
13
|
-
allow(subject).to receive(:execute).and_return(["stdout", "stderr", 0])
|
|
14
|
-
output = subject.run(%W[foo])
|
|
15
|
-
expect(output).to eq "stdout"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "uses stderr for error messages" do
|
|
19
|
-
allow(subject).to receive(:execute).and_return(["", "stderr", 1])
|
|
20
|
-
expect { subject.run(%W[foo]) }
|
|
21
|
-
.to raise_error(MiniMagick::Error, /`foo`.*stderr/m)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "raises an error when executable wasn't found" do
|
|
25
|
-
allow(subject).to receive(:execute).and_return(["", "not found", 127])
|
|
26
|
-
expect { subject.run(%W[foo]) }
|
|
27
|
-
.to raise_error(MiniMagick::Error, /not found/)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "raises errors only in whiny mode" do
|
|
31
|
-
subject = described_class.new(false)
|
|
32
|
-
allow(subject).to receive(:execute).and_return(["stdout", "", 127])
|
|
33
|
-
expect(subject.run(%W[foo])).to eq "stdout"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "prints to stderr output to $stderr in non-whiny mode" do
|
|
37
|
-
subject = described_class.new(false)
|
|
38
|
-
allow(subject).to receive(:execute).and_return(["", "stderr", 1])
|
|
39
|
-
expect { subject.run(%W[foo]) }.to output("stderr").to_stderr
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "#execute" do
|
|
44
|
-
it "executes the command in the shell" do
|
|
45
|
-
stdout, * = subject.execute(%W[identify #{image_path(:gif)}])
|
|
46
|
-
expect(stdout).to match("GIF")
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "logs the command and execution time in debug mode" do
|
|
50
|
-
allow(MiniMagick).to receive(:debug).and_return(true)
|
|
51
|
-
expect { subject.execute(%W[identify #{image_path(:gif)}]) }.
|
|
52
|
-
to output(/\[\d+.\d+s\] identify #{image_path(:gif)}/).to_stdout
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "returns an appropriate response when command wasn't found" do
|
|
56
|
-
stdout, stderr, code = subject.execute(%W[unexisting command])
|
|
57
|
-
expect(code).to eq 127
|
|
58
|
-
expect(stderr).to match(/not found/)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "doesn't break on spaces" do
|
|
62
|
-
stdout, * = subject.execute(["identify", "-format", "%w %h", image_path])
|
|
63
|
-
expect(stdout).to match(/\d+ \d+/)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe MiniMagick::Tool do
|
|
4
|
-
subject { MiniMagick::Tool::Identify.new }
|
|
5
|
-
|
|
6
|
-
describe "#call" do
|
|
7
|
-
it "calls the shell to run the command" do
|
|
8
|
-
subject << image_path(:gif)
|
|
9
|
-
output = subject.call
|
|
10
|
-
expect(output).to match("GIF")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "strips the output" do
|
|
14
|
-
subject << image_path
|
|
15
|
-
output = subject.call
|
|
16
|
-
expect(output).not_to end_with("\n")
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe ".new" do
|
|
21
|
-
it "accepts a block, and immediately executes the command" do
|
|
22
|
-
output = described_class.new("identify") do |builder|
|
|
23
|
-
builder << image_path(:gif)
|
|
24
|
-
end
|
|
25
|
-
expect(output).to match("GIF")
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe "#command" do
|
|
30
|
-
it "includes the executable and the arguments" do
|
|
31
|
-
allow(subject).to receive(:args).and_return(%W[-list Command])
|
|
32
|
-
expect(subject.command).to include(*%W[identify -list Command])
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe "#executable" do
|
|
37
|
-
it "prepends 'gm' to the command list when using GraphicsMagick" do
|
|
38
|
-
allow(MiniMagick).to receive(:cli).and_return(:graphicsmagick)
|
|
39
|
-
expect(subject.executable).to eq %W[gm identify]
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "respects #cli_path" do
|
|
43
|
-
allow(MiniMagick).to receive(:cli).and_return(:imagemagick)
|
|
44
|
-
allow(MiniMagick).to receive(:cli_path).and_return("path/to/cli")
|
|
45
|
-
expect(subject.executable).to eq %W[path/to/cli/identify]
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe "#<<" do
|
|
50
|
-
it "adds argument to the args list" do
|
|
51
|
-
subject << "foo" << "bar" << 123
|
|
52
|
-
expect(subject.args).to eq %W[foo bar 123]
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe "#merge!" do
|
|
57
|
-
it "adds arguments to the args list" do
|
|
58
|
-
subject << "pre-existing"
|
|
59
|
-
subject.merge! ["foo", 123]
|
|
60
|
-
expect(subject.args).to eq %W[pre-existing foo 123]
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "#+" do
|
|
65
|
-
it "switches the last option to + form" do
|
|
66
|
-
subject.help
|
|
67
|
-
subject.help.+
|
|
68
|
-
subject.debug.+ "foo"
|
|
69
|
-
subject.debug.+ 8, "bar"
|
|
70
|
-
expect(subject.args).to eq %W[-help +help +debug foo +debug 8 bar]
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
["ImageMagick", "GraphicsMagick"].each do |cli|
|
|
75
|
-
context "with #{cli}", cli: cli.downcase.to_sym do
|
|
76
|
-
it "adds dynamically generated operator methods" do
|
|
77
|
-
subject.help.depth(8)
|
|
78
|
-
expect(subject.args).to eq %W[-help -depth 8]
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "doesn't just delegate to #method_missing" do
|
|
82
|
-
expect(subject.class.instance_methods).to include(:help)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "adds dynamically generated creation operator methods" do
|
|
86
|
-
subject.radial_gradient.canvas "khaki"
|
|
87
|
-
expect(subject.args).to eq %W[radial-gradient: canvas:khaki]
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "resets the dynamically generated operator methods on CLI change" do
|
|
93
|
-
MiniMagick.cli = :imagemagick
|
|
94
|
-
expect(subject).to respond_to(:quiet)
|
|
95
|
-
|
|
96
|
-
MiniMagick.cli = :graphicsmagick
|
|
97
|
-
expect(subject).not_to respond_to(:quiet)
|
|
98
|
-
expect(subject).to respond_to(:ping)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it "doesn't raise errors when false is passed to the constructor" do
|
|
102
|
-
subject.help
|
|
103
|
-
subject.call(false)
|
|
104
|
-
|
|
105
|
-
MiniMagick::Tool::Identify.new(false, &:help)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe MiniMagick::Utilities do
|
|
4
|
-
describe ".which" do
|
|
5
|
-
it "identifies when mogrify exists" do
|
|
6
|
-
expect(MiniMagick::Utilities.which('mogrify')).not_to be_nil
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "identifies when gm exists" do
|
|
10
|
-
expect(MiniMagick::Utilities.which('gm')).not_to be_nil
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "returns nil on nonexistent executables" do
|
|
14
|
-
expect(MiniMagick::Utilities.which('yogrify')).to be_nil
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
RSpec.describe MiniMagick do
|
|
4
|
-
describe ".imagemagick?" do
|
|
5
|
-
it "returns true if CLI is minimagick" do
|
|
6
|
-
allow(described_class).to receive(:cli).and_return(:imagemagick)
|
|
7
|
-
expect(described_class.imagemagick?).to eq true
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "returns false if CLI isn't minimagick" do
|
|
11
|
-
allow(described_class).to receive(:cli).and_return(:graphicsmagick)
|
|
12
|
-
expect(described_class.imagemagick?).to eq false
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe ".graphicsmagick?" do
|
|
17
|
-
it "returns true if CLI is graphicsmagick" do
|
|
18
|
-
allow(described_class).to receive(:cli).and_return(:graphicsmagick)
|
|
19
|
-
expect(described_class.graphicsmagick?).to eq true
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "returns false if CLI isn't graphicsmagick" do
|
|
23
|
-
allow(described_class).to receive(:cli).and_return(:imagemagick)
|
|
24
|
-
expect(described_class.graphicsmagick?).to eq false
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe ".cli_version" do
|
|
29
|
-
it "returns ImageMagick's version" do
|
|
30
|
-
allow(described_class).to receive(:cli).and_return(:imagemagick)
|
|
31
|
-
expect(described_class.cli_version).to match(/^\d+\.\d+\.\d+-\d+$/)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "returns GraphicsMagick's version" do
|
|
35
|
-
allow(described_class).to receive(:cli).and_return(:graphicsmagick)
|
|
36
|
-
expect(described_class.cli_version).to match(/^\d+\.\d+\.\d+$/)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require "bundler/setup"
|
|
2
|
-
require "mini_magick"
|
|
3
|
-
require "pry"
|
|
4
|
-
|
|
5
|
-
require_relative "support/helpers"
|
|
6
|
-
|
|
7
|
-
RSpec.configure do |config|
|
|
8
|
-
config.disable_monkey_patching!
|
|
9
|
-
config.formatter = "documentation"
|
|
10
|
-
config.color = true
|
|
11
|
-
config.fail_fast = true unless ENV["CI"]
|
|
12
|
-
|
|
13
|
-
[:imagemagick, :graphicsmagick].each do |cli|
|
|
14
|
-
config.around(cli: cli) do |example|
|
|
15
|
-
MiniMagick.with_cli(cli) { example.run }
|
|
16
|
-
end
|
|
17
|
-
config.around(skip_cli: cli) do |example|
|
|
18
|
-
example.run unless example.metadata[:cli] == cli
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
data/spec/support/helpers.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require "tempfile"
|
|
2
|
-
|
|
3
|
-
module Helpers
|
|
4
|
-
def image_path(type = :default)
|
|
5
|
-
if type != :without_extension
|
|
6
|
-
File.join("spec/fixtures",
|
|
7
|
-
case type
|
|
8
|
-
when :default, :jpg then "default.jpg"
|
|
9
|
-
when :animation, :gif then "animation.gif"
|
|
10
|
-
when :pdf then "document.pdf"
|
|
11
|
-
when :psd then "image.psd"
|
|
12
|
-
when :exif then "exif.jpg"
|
|
13
|
-
when :not then "not_an_image.rb"
|
|
14
|
-
else
|
|
15
|
-
fail "image #{type.inspect} doesn't exist"
|
|
16
|
-
end
|
|
17
|
-
)
|
|
18
|
-
else
|
|
19
|
-
path = random_path
|
|
20
|
-
FileUtils.cp image_path, path
|
|
21
|
-
path
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def image_url
|
|
26
|
-
"https://avatars2.githubusercontent.com/u/795488?v=2&s=40"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def random_path(basename = "")
|
|
30
|
-
@tempfile = Tempfile.open(basename)
|
|
31
|
-
@tempfile.path
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
RSpec.configure do |config|
|
|
36
|
-
config.include Helpers
|
|
37
|
-
end
|