mojo_magick 0.5.7 → 0.6.5
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/.circleci/config.yml +25 -0
- data/.github/dependabot.yml +8 -0
- data/.rubocop-common.yml +99 -0
- data/.rubocop-performance.yml +2 -0
- data/.rubocop.yml +11 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +48 -15
- data/README.md +40 -4
- data/Rakefile +15 -6
- data/examples/animated_gif.rb +11 -13
- data/examples/composite.rb +11 -13
- data/init.rb +1 -1
- data/lib/image_magick/fonts.rb +4 -11
- data/lib/mojo_magick.rb +93 -76
- data/lib/mojo_magick/command_status.rb +1 -1
- data/lib/mojo_magick/commands.rb +32 -0
- data/lib/mojo_magick/errors.rb +2 -0
- data/lib/mojo_magick/font.rb +1 -2
- data/lib/mojo_magick/opt_builder.rb +16 -27
- data/lib/mojo_magick/util/font_parser.rb +43 -0
- data/lib/mojo_magick/util/parser.rb +11 -56
- data/lib/mojo_magick/version.rb +1 -1
- data/mojo_magick.gemspec +19 -16
- data/test/fixtures/roll with it.jpg +0 -0
- data/test/{parser_test.rb → font_parser_test.rb} +7 -7
- data/test/font_test.rb +5 -5
- data/test/mojo_magick_test.rb +99 -88
- data/test/opt_builder_test.rb +99 -80
- data/test/test_helper.rb +7 -6
- metadata +47 -16
- data/lib/image_magick/resource_limits.rb +0 -91
- data/lib/initializers/hash.rb +0 -12
- data/test/fonts_test.rb +0 -11
- data/test/resource_limits_test.rb +0 -49
data/test/opt_builder_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
|
3
3
|
class MojoMagickOptBuilderTest < MiniTest::Test
|
4
4
|
# These tests make the assumption that if we call #raw_command with the
|
@@ -10,120 +10,139 @@ class MojoMagickOptBuilderTest < MiniTest::Test
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_annotate
|
13
|
-
@builder.annotate
|
14
|
-
assert_equal
|
13
|
+
@builder.annotate "blah"
|
14
|
+
assert_equal %w[-annotate 0 blah], @builder.to_a
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_annotate_with_escapeable_string
|
18
|
-
@builder.annotate
|
19
|
-
assert_equal
|
18
|
+
@builder.annotate "it's"
|
19
|
+
assert_equal %w[-annotate 0 it's], @builder.to_a
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
@builder.annotate
|
24
|
-
assert_equal
|
22
|
+
def test_annotate_with_multiple_args
|
23
|
+
@builder.annotate "5 it's"
|
24
|
+
assert_equal ["-annotate", "0", "5 it's"], @builder.to_a
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_annotate_with_geometry_args
|
28
|
+
@builder.annotate "this thing", geometry: 3
|
29
|
+
assert_equal ["-annotate", "3", "this thing"], @builder.to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_annotate_with_full_array_args
|
33
|
+
@builder.annotate "this", "thing", geometry: 3
|
34
|
+
assert_equal ["-annotate", "3", "thisthing"], @builder.to_a
|
25
35
|
end
|
26
36
|
|
27
37
|
def test_option_builder_with_blocks
|
28
38
|
# Passing in basic commands produces a string
|
29
|
-
|
30
|
-
|
31
|
-
b.background 'red'
|
39
|
+
@builder.image_block do
|
40
|
+
@builder.background "red"
|
32
41
|
end
|
33
|
-
|
34
|
-
|
42
|
+
@builder.image_block do
|
43
|
+
@builder.background "blue"
|
35
44
|
end
|
36
|
-
assert_equal '\( -background red \) \( -background blue \)',
|
45
|
+
assert_equal ['\(', "-background", "red", '\)', '\(', "-background", "blue", '\)'], @builder.to_a
|
37
46
|
end
|
38
47
|
|
39
48
|
def test_option_builder_with_hex_colors
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal '-background "#000000"', b.to_s
|
49
|
+
@builder.background "#000000"
|
50
|
+
assert_equal %w[-background #000000], @builder.to_a
|
43
51
|
end
|
44
52
|
|
45
53
|
def test_option_builder
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assert_equal '-strip -repage', b.to_s
|
54
|
+
@builder.strip
|
55
|
+
@builder.repage
|
56
|
+
assert_equal %w[-strip -repage], @builder.to_a
|
57
|
+
end
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
def test_opt_builder_chaining_commands
|
60
|
+
assert_equal %w[-strip -repage], @builder.strip.repage.to_a
|
61
|
+
end
|
55
62
|
|
63
|
+
def test_opt_builder_interpreting_bang_suffix
|
56
64
|
# Bang (!) indicates the plus version of commands
|
57
|
-
b = MojoMagick::OptBuilder.new
|
58
|
-
b.repage
|
59
|
-
b.repage!
|
60
|
-
assert_equal '-repage +repage', b.to_s
|
61
65
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
b.opt2
|
67
|
-
assert_equal '-opt1 a ! b ! -opt2', b.to_s
|
66
|
+
@builder.repage
|
67
|
+
@builder.repage!
|
68
|
+
assert_equal %w[-repage +repage], @builder.to_a
|
69
|
+
end
|
68
70
|
|
71
|
+
def test_opt_builder_pushing_raw_data
|
69
72
|
# Treats an array of raw data as different arguments
|
70
|
-
b = MojoMagick::OptBuilder.new
|
71
|
-
b << ['leave this data', 'alone']
|
72
|
-
assert_equal 'leave this data alone', b.to_s
|
73
|
-
|
74
|
-
# String includes command arguments
|
75
|
-
b = MojoMagick::OptBuilder.new
|
76
|
-
b.extent '256x256+0+0'
|
77
|
-
b.crop '64x64'
|
78
|
-
assert_equal '-extent 256x256+0+0 -crop 64x64', b.to_s
|
79
|
-
|
80
|
-
# Arguments are quoted (doublequote) if appropriate
|
81
|
-
b = MojoMagick::OptBuilder.new
|
82
|
-
b.comment 'white space'
|
83
|
-
b.comment 'w&b'
|
84
|
-
b.crop '6x6^'
|
85
|
-
assert_equal '-comment "white space" -comment "w&b" -crop "6x6^"', b.to_s
|
86
|
-
|
87
|
-
# Existing doublequotes are escaped
|
88
|
-
b = MojoMagick::OptBuilder.new
|
89
|
-
b.comment 'Fred "Woot" Rook'
|
90
|
-
assert_equal '-comment "Fred \"Woot\" Rook"', b.to_s
|
91
73
|
|
74
|
+
@builder << ["leave this data", "alone"]
|
75
|
+
assert_equal ["leave this data", "alone"], @builder.to_a
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_opt_builder_complex_command_arg
|
79
|
+
@builder.extent "256x256+0+0"
|
80
|
+
@builder.crop "64x64"
|
81
|
+
assert_equal %w[-extent 256x256+0+0 -crop 64x64], @builder.to_a
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_opt_builder_multi_arg_command_quoting
|
92
85
|
# Multi-argument commands should not be quoted together
|
93
|
-
b = MojoMagick::OptBuilder.new
|
94
|
-
b.set 'comment', 'the "best" comment'
|
95
|
-
assert_equal '-set comment "the \"best\" comment"', b.to_s
|
96
86
|
|
87
|
+
@builder.set "comment", 'the "best" comment'
|
88
|
+
assert_equal ["-set", "comment", "the \"best\" comment"], @builder.to_a
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_opt_builder_with_custom_commands_and_raw_data
|
92
|
+
# Accepts raw data as-is
|
93
|
+
|
94
|
+
@builder.opt1
|
95
|
+
@builder << "a ! b !"
|
96
|
+
@builder.opt2
|
97
|
+
assert_equal ["-opt1", "a ! b !", "-opt2"], @builder.to_a
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_opt_builder_file_and_files
|
97
101
|
# File and files are helper methods
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
assert_equal
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
102
|
+
|
103
|
+
@builder.files "source.jpg", "source2.jpg"
|
104
|
+
@builder.append
|
105
|
+
@builder.crop "64x64"
|
106
|
+
@builder.file "dest%d.jpg"
|
107
|
+
assert_equal %w[source.jpg source2.jpg -append -crop 64x64 dest%d.jpg], @builder.to_a
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_opt_builder_file_preserves_whitespace
|
111
|
+
@builder.file "probably on windows.jpg"
|
112
|
+
assert_equal ["probably on windows.jpg"], @builder.to_a
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_opt_builder_comment
|
116
|
+
@builder.comment "white space"
|
117
|
+
@builder.comment "w&b"
|
118
|
+
@builder.crop "6x6^"
|
119
|
+
assert_equal ["-comment", "white space", "-comment", "w&b", "-crop", "6x6^"], @builder.to_a
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_opt_builder_comment_with_quoted_elements
|
123
|
+
@builder.comment 'Fred "Woot" Rook'
|
124
|
+
assert_equal ["-comment", "Fred \"Woot\" Rook"], @builder.to_a
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_opt_builder_blob_writes_data_to_temp_file
|
128
|
+
@builder.blob "binary data"
|
129
|
+
|
130
|
+
filename = @builder.to_a.first
|
131
|
+
File.open(filename, "rb") do |f|
|
132
|
+
assert_equal "binary data", f.read
|
116
133
|
end
|
134
|
+
end
|
117
135
|
|
136
|
+
def test_opt_builder_label
|
118
137
|
# label for text should use 'label:"the string"' if specified
|
119
138
|
[%w[mylabel mylabel],
|
120
139
|
['my " label', '"my \" label"'],
|
121
|
-
[
|
140
|
+
["Rock it, cuz i said so!", '"Rock it, cuz i said so!"'],
|
122
141
|
["it's like this", '"it\'s like this"'],
|
123
|
-
[
|
142
|
+
["\#$%^&*", '"#$%^&*"']].each do |labels|
|
124
143
|
b = MojoMagick::OptBuilder.new
|
125
144
|
b.label labels[0]
|
126
|
-
assert_equal "label:#{labels[1]}", b.
|
145
|
+
assert_equal ["label:#{labels[1]}"], b.to_a
|
127
146
|
end
|
128
147
|
end
|
129
148
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require "minitest/autorun"
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
|
6
|
+
require "fileutils"
|
7
|
+
require "tempfile"
|
metadata
CHANGED
@@ -1,17 +1,45 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojo_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Midgley
|
8
8
|
- Elliot Nelson
|
9
9
|
- Jon Rogers
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundle-audit
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
15
43
|
- !ruby/object:Gem::Dependency
|
16
44
|
name: minitest
|
17
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +69,7 @@ dependencies:
|
|
41
69
|
- !ruby/object:Gem::Version
|
42
70
|
version: '0'
|
43
71
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
72
|
+
name: rubocop
|
45
73
|
requirement: !ruby/object:Gem::Requirement
|
46
74
|
requirements:
|
47
75
|
- - ">="
|
@@ -55,7 +83,7 @@ dependencies:
|
|
55
83
|
- !ruby/object:Gem::Version
|
56
84
|
version: '0'
|
57
85
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
86
|
+
name: rubocop-performance
|
59
87
|
requirement: !ruby/object:Gem::Requirement
|
60
88
|
requirements:
|
61
89
|
- - ">="
|
@@ -76,7 +104,12 @@ executables: []
|
|
76
104
|
extensions: []
|
77
105
|
extra_rdoc_files: []
|
78
106
|
files:
|
107
|
+
- ".circleci/config.yml"
|
108
|
+
- ".github/dependabot.yml"
|
79
109
|
- ".gitignore"
|
110
|
+
- ".rubocop-common.yml"
|
111
|
+
- ".rubocop-performance.yml"
|
112
|
+
- ".rubocop.yml"
|
80
113
|
- ".ruby-version"
|
81
114
|
- Gemfile
|
82
115
|
- Gemfile.lock
|
@@ -87,25 +120,24 @@ files:
|
|
87
120
|
- examples/composite.rb
|
88
121
|
- init.rb
|
89
122
|
- lib/image_magick/fonts.rb
|
90
|
-
- lib/image_magick/resource_limits.rb
|
91
|
-
- lib/initializers/hash.rb
|
92
123
|
- lib/mojo_magick.rb
|
93
124
|
- lib/mojo_magick/command_status.rb
|
125
|
+
- lib/mojo_magick/commands.rb
|
94
126
|
- lib/mojo_magick/errors.rb
|
95
127
|
- lib/mojo_magick/font.rb
|
96
128
|
- lib/mojo_magick/opt_builder.rb
|
129
|
+
- lib/mojo_magick/util/font_parser.rb
|
97
130
|
- lib/mojo_magick/util/parser.rb
|
98
131
|
- lib/mojo_magick/version.rb
|
99
132
|
- mojo_magick.gemspec
|
100
133
|
- test/fixtures/5742.jpg
|
101
134
|
- test/fixtures/not_an_image.jpg
|
135
|
+
- test/fixtures/roll with it.jpg
|
102
136
|
- test/fixtures/zero_byte_image.jpg
|
137
|
+
- test/font_parser_test.rb
|
103
138
|
- test/font_test.rb
|
104
|
-
- test/fonts_test.rb
|
105
139
|
- test/mojo_magick_test.rb
|
106
140
|
- test/opt_builder_test.rb
|
107
|
-
- test/parser_test.rb
|
108
|
-
- test/resource_limits_test.rb
|
109
141
|
- test/test_helper.rb
|
110
142
|
homepage: http://github.com/rcode5/mojo_magick
|
111
143
|
licenses:
|
@@ -127,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
159
|
requirements:
|
128
160
|
- - ">="
|
129
161
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
162
|
+
version: 2.6.0
|
131
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
164
|
requirements:
|
133
165
|
- - ">="
|
@@ -135,18 +167,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
167
|
version: '0'
|
136
168
|
requirements: []
|
137
169
|
rubygems_version: 3.0.3
|
138
|
-
signing_key:
|
170
|
+
signing_key:
|
139
171
|
specification_version: 4
|
140
|
-
summary: mojo_magick-0.5
|
172
|
+
summary: mojo_magick-0.6.5
|
141
173
|
test_files:
|
142
174
|
- test/fixtures/5742.jpg
|
143
175
|
- test/fixtures/not_an_image.jpg
|
176
|
+
- test/fixtures/roll with it.jpg
|
144
177
|
- test/fixtures/zero_byte_image.jpg
|
178
|
+
- test/font_parser_test.rb
|
145
179
|
- test/font_test.rb
|
146
|
-
- test/fonts_test.rb
|
147
180
|
- test/mojo_magick_test.rb
|
148
181
|
- test/opt_builder_test.rb
|
149
|
-
- test/parser_test.rb
|
150
|
-
- test/resource_limits_test.rb
|
151
182
|
- test/test_helper.rb
|
152
183
|
...
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# This module provides some mix-in methods to permit resource limitation commands in MojoMagick
|
2
|
-
module ImageMagick
|
3
|
-
module ResourceLimits
|
4
|
-
@@resource_limits = {}
|
5
|
-
|
6
|
-
# controls limits on memory and other resources for imagemagick.
|
7
|
-
# possible values for type can include:
|
8
|
-
# Area, Disk, File, Map, or Memory
|
9
|
-
# value is byte size for everything but Disk, where it's number of files
|
10
|
-
# type can be string or symbol.
|
11
|
-
# Just limiting Memory will not solve problems with imagemagick going out of
|
12
|
-
# control with resource consumption on certain bad files. You have to set disk,
|
13
|
-
# area and map limits too. Read up on imagemagick website for more.
|
14
|
-
# Different options have different units
|
15
|
-
# DISK: N GB
|
16
|
-
# AREA, MAP, MEMORY: N MB
|
17
|
-
# FILE: N num file handles
|
18
|
-
# Examples:
|
19
|
-
# # set disk to 5 gigabytes limit
|
20
|
-
# MiniMagick::Image::set_limit(:disk => 5)
|
21
|
-
# # set memory to 32mb, map to 64mb and disk to 0
|
22
|
-
# MiniMagick::Image::set_limit(:memory => 32, 'map' => 64, 'disk' => 0)
|
23
|
-
def set_limits(options)
|
24
|
-
options.each do |resource, value|
|
25
|
-
@@resource_limits[resource.to_s.downcase.to_sym] = value.to_s
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# remove a limit
|
30
|
-
def remove_limits(*options)
|
31
|
-
@@resource_limits.delete_if do |resource, _value|
|
32
|
-
idx = options.index(resource)
|
33
|
-
resource == options.values_at(idx)[0].to_s.downcase.to_sym if idx
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# remove limits from resources
|
38
|
-
def unset_limits(options = {})
|
39
|
-
@@resource_limits = {}
|
40
|
-
if options[:unset_env]
|
41
|
-
ENV['MAGICK_AREA_LIMIT'] = nil
|
42
|
-
ENV['MAGICK_MAP_LIMIT'] = nil
|
43
|
-
ENV['MAGICK_MEMORY_LIMIT'] = nil
|
44
|
-
ENV['MAGICK_DISK_LIMIT'] = nil
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# returns the default limits that imagemagick is using, when run with no "-limit" parameters
|
49
|
-
# options:
|
50
|
-
# :show_actual_values => true (default false) - will return integers instead of readable values
|
51
|
-
def get_default_limits(options = {})
|
52
|
-
parse_limits(options.merge(get_current_limits: false))
|
53
|
-
end
|
54
|
-
|
55
|
-
# returns the limits that imagemagick is running based on any "set_limits" calls
|
56
|
-
def get_current_limits(options = {})
|
57
|
-
parse_limits(options.merge(get_current_limits: true))
|
58
|
-
end
|
59
|
-
|
60
|
-
alias get_limits get_current_limits
|
61
|
-
|
62
|
-
def parse_limits(options)
|
63
|
-
show_actual_values = options[:show_actual_values]
|
64
|
-
if options[:get_current_limits]
|
65
|
-
status = execute('identify', '-list resource')
|
66
|
-
raw_limits = status.return_value
|
67
|
-
else
|
68
|
-
# we run a raw shell command here to obtain
|
69
|
-
# limits without applying command line limit params
|
70
|
-
raw_limits = `identify -list resource`
|
71
|
-
end
|
72
|
-
actual_values, readable_values = parser.parse_limits(raw_limits)
|
73
|
-
show_actual_values ? actual_values : readable_values
|
74
|
-
end # parse_limits
|
75
|
-
|
76
|
-
# returns a string suitable for passing as a set of imagemagick params
|
77
|
-
# that contains all the limit constraints
|
78
|
-
def get_limits_as_params
|
79
|
-
retval = ''
|
80
|
-
# we upcase the value here for newer versions of ImageMagick (>=6.8.x)
|
81
|
-
@@resource_limits.each do |type, value|
|
82
|
-
retval += " -limit #{type} #{value.upcase} "
|
83
|
-
end
|
84
|
-
retval
|
85
|
-
end
|
86
|
-
|
87
|
-
def parser
|
88
|
-
@parser ||= MojoMagick::Util::Parser.new
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|