mojo_magick 0.5.5 → 0.6.3

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.
@@ -1,7 +1,6 @@
1
- require File::join(File::dirname(__FILE__), 'test_helper')
2
-
3
- class MojoMagickOptBuilderTest < MiniTest::Unit::TestCase
1
+ require_relative "test_helper"
4
2
 
3
+ class MojoMagickOptBuilderTest < MiniTest::Test
5
4
  # These tests make the assumption that if we call #raw_command with the
6
5
  # correct strings, ImageMagick itself will operate correctly. We're only
7
6
  # verifying that the option builder produces the correct strings
@@ -11,122 +10,139 @@ class MojoMagickOptBuilderTest < MiniTest::Unit::TestCase
11
10
  end
12
11
 
13
12
  def test_annotate
14
- @builder.annotate 'blah'
15
- assert_equal '-annotate 0 blah', @builder.to_s
13
+ @builder.annotate "blah"
14
+ assert_equal %w[-annotate 0 blah], @builder.to_a
16
15
  end
17
16
 
18
17
  def test_annotate_with_escapeable_string
19
- @builder.annotate 'it\'s'
20
- assert_equal '-annotate 0 "it\'s"', @builder.to_s
18
+ @builder.annotate "it's"
19
+ assert_equal %w[-annotate 0 it's], @builder.to_a
20
+ end
21
+
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
21
30
  end
22
31
 
23
- def test_annotate_with_full_args
24
- @builder.annotate '5 it\'s'
25
- assert_equal '-annotate 5 "it\'s"', @builder.to_s
32
+ def test_annotate_with_full_array_args
33
+ @builder.annotate "this", "thing", geometry: 3
34
+ assert_equal ["-annotate", "3", "thisthing"], @builder.to_a
26
35
  end
27
36
 
28
37
  def test_option_builder_with_blocks
29
38
  # Passing in basic commands produces a string
30
- b = MojoMagick::OptBuilder.new
31
- b.image_block do
32
- b.background 'red'
39
+ @builder.image_block do
40
+ @builder.background "red"
33
41
  end
34
- b.image_block do
35
- b.background 'blue'
42
+ @builder.image_block do
43
+ @builder.background "blue"
36
44
  end
37
- assert_equal '\( -background red \) \( -background blue \)', b.to_s
45
+ assert_equal ['\(', "-background", "red", '\)', '\(', "-background", "blue", '\)'], @builder.to_a
38
46
  end
39
47
 
40
- def test_option_builder_with_hex_colors
41
- b = MojoMagick::OptBuilder.new
42
- b.background '#000000'
43
- assert_equal '-background "#000000"', b.to_s
48
+ def test_option_builder_with_hex_colors
49
+ @builder.background "#000000"
50
+ assert_equal %w[-background #000000], @builder.to_a
44
51
  end
45
52
 
46
53
  def test_option_builder
47
- # Passing in basic commands produces a string
48
- b = MojoMagick::OptBuilder.new
49
- b.strip
50
- b.repage
51
- assert_equal '-strip -repage', b.to_s
54
+ @builder.strip
55
+ @builder.repage
56
+ assert_equal %w[-strip -repage], @builder.to_a
57
+ end
52
58
 
53
- # Chaining commands works
54
- b = MojoMagick::OptBuilder.new.strip.repage
55
- assert_equal '-strip -repage', b.to_s
59
+ def test_opt_builder_chaining_commands
60
+ assert_equal %w[-strip -repage], @builder.strip.repage.to_a
61
+ end
56
62
 
63
+ def test_opt_builder_interpreting_bang_suffix
57
64
  # Bang (!) indicates the plus version of commands
58
- b = MojoMagick::OptBuilder.new
59
- b.repage
60
- b.repage!
61
- assert_equal '-repage +repage', b.to_s
62
65
 
63
- # Accepts raw data as-is
64
- b = MojoMagick::OptBuilder.new
65
- b.opt1
66
- b << 'a ! b !'
67
- b.opt2
68
- 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
69
70
 
71
+ def test_opt_builder_pushing_raw_data
70
72
  # Treats an array of raw data as different arguments
71
- b = MojoMagick::OptBuilder.new
72
- b << ['leave this data','alone']
73
- assert_equal 'leave this data alone', b.to_s
74
-
75
- # String includes command arguments
76
- b = MojoMagick::OptBuilder.new
77
- b.extent '256x256+0+0'
78
- b.crop '64x64'
79
- assert_equal '-extent 256x256+0+0 -crop 64x64', b.to_s
80
-
81
- # Arguments are quoted (doublequote) if appropriate
82
- b = MojoMagick::OptBuilder.new
83
- b.comment 'white space'
84
- b.comment 'w&b'
85
- b.crop '6x6^'
86
- assert_equal '-comment "white space" -comment "w&b" -crop "6x6^"', b.to_s
87
-
88
- # Existing doublequotes are escaped
89
- b = MojoMagick::OptBuilder.new
90
- b.comment 'Fred "Woot" Rook'
91
- assert_equal '-comment "Fred \"Woot\" Rook"', b.to_s
92
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
93
85
  # Multi-argument commands should not be quoted together
94
- b = MojoMagick::OptBuilder.new
95
- b.set 'comment', 'the "best" comment'
96
- assert_equal '-set comment "the \"best\" comment"', b.to_s
97
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
98
101
  # File and files are helper methods
99
- b = MojoMagick::OptBuilder.new
100
- b.files 'source.jpg', 'source2.jpg'
101
- b.append
102
- b.crop '64x64'
103
- b.file 'dest%d.jpg'
104
- assert_equal 'source.jpg source2.jpg -append -crop 64x64 dest%d.jpg', b.to_s
105
-
106
- # Files are quoted (doublequote) if appropriate
107
- b = MojoMagick::OptBuilder.new
108
- b.file 'probably on windows.jpg'
109
- assert_equal '"probably on windows.jpg"', b.to_s
110
-
111
- # Blob is a shortcut for the #tempfile helper method
112
- b = MojoMagick::OptBuilder.new
113
- b.blob 'binary data'
114
- filename = b.to_s
115
- File.open(filename, 'rb') do |f|
116
- assert_equal 'binary data', f.read
117
- end
118
102
 
119
- #label for text should use 'label:"the string"' if specified
120
- [[ 'mylabel', 'mylabel' ],
121
- [ 'my " label', '"my \" label"' ],
122
- [ 'Rock it, cuz i said so!', '"Rock it, cuz i said so!"'],
123
- [ "it's like this", '"it\'s like this"'],
124
- [ '#$%^&*', '"#$%^&*"']].each do |labels|
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"
125
129
 
130
+ filename = @builder.to_a.first
131
+ File.open(filename, "rb") do |f|
132
+ assert_equal "binary data", f.read
133
+ end
134
+ end
135
+
136
+ def test_opt_builder_label
137
+ # label for text should use 'label:"the string"' if specified
138
+ [%w[mylabel mylabel],
139
+ ['my " label', '"my \" label"'],
140
+ ["Rock it, cuz i said so!", '"Rock it, cuz i said so!"'],
141
+ ["it's like this", '"it\'s like this"'],
142
+ ["\#$%^&*", '"#$%^&*"']].each do |labels|
126
143
  b = MojoMagick::OptBuilder.new
127
144
  b.label labels[0]
128
- assert_equal "label:#{labels[1]}", b.to_s
145
+ assert_equal ["label:#{labels[1]}"], b.to_a
129
146
  end
130
-
131
147
  end
132
148
  end
@@ -1,6 +1,8 @@
1
- require 'test/unit'
2
- require File::expand_path(File::join(File::dirname(__FILE__), '..', 'init'))
3
- require 'fileutils'
4
- require 'tempfile'
5
- require 'rspec/expectations'
1
+ require "simplecov"
2
+ SimpleCov.start
6
3
 
4
+ require "minitest/autorun"
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
6
+ require "fileutils"
7
+ require "tempfile"
8
+ require "rspec/expectations"
metadata CHANGED
@@ -1,19 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojo_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.3
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: 2015-05-31 00:00:00.000000000 Z
13
+ date: 2021-01-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rake
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
17
31
  requirement: !ruby/object:Gem::Requirement
18
32
  requirements:
19
33
  - - ">="
@@ -27,7 +41,21 @@ dependencies:
27
41
  - !ruby/object:Gem::Version
28
42
  version: '0'
29
43
  - !ruby/object:Gem::Dependency
30
- name: simplecov
44
+ name: minitest
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
31
59
  requirement: !ruby/object:Gem::Requirement
32
60
  requirements:
33
61
  - - ">="
@@ -54,6 +82,34 @@ dependencies:
54
82
  - - ">="
55
83
  - !ruby/object:Gem::Version
56
84
  version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rubocop
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop-performance
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
57
113
  description: Simple Ruby stateless module interface to imagemagick.
58
114
  email:
59
115
  - science@misuse.org
@@ -62,7 +118,13 @@ executables: []
62
118
  extensions: []
63
119
  extra_rdoc_files: []
64
120
  files:
121
+ - ".circleci/config.yml"
122
+ - ".github/dependabot.yml"
65
123
  - ".gitignore"
124
+ - ".rubocop-common.yml"
125
+ - ".rubocop-performance.yml"
126
+ - ".rubocop-rspec.yml"
127
+ - ".rubocop.yml"
66
128
  - ".ruby-version"
67
129
  - Gemfile
68
130
  - Gemfile.lock
@@ -73,25 +135,24 @@ files:
73
135
  - examples/composite.rb
74
136
  - init.rb
75
137
  - lib/image_magick/fonts.rb
76
- - lib/image_magick/resource_limits.rb
77
- - lib/initializers/hash.rb
78
138
  - lib/mojo_magick.rb
79
139
  - lib/mojo_magick/command_status.rb
140
+ - lib/mojo_magick/commands.rb
80
141
  - lib/mojo_magick/errors.rb
81
142
  - lib/mojo_magick/font.rb
82
143
  - lib/mojo_magick/opt_builder.rb
144
+ - lib/mojo_magick/util/font_parser.rb
83
145
  - lib/mojo_magick/util/parser.rb
84
146
  - lib/mojo_magick/version.rb
85
147
  - mojo_magick.gemspec
86
148
  - test/fixtures/5742.jpg
87
149
  - test/fixtures/not_an_image.jpg
150
+ - test/fixtures/roll with it.jpg
88
151
  - test/fixtures/zero_byte_image.jpg
152
+ - test/font_parser_test.rb
89
153
  - test/font_test.rb
90
- - test/fonts_test.rb
91
154
  - test/mojo_magick_test.rb
92
155
  - test/opt_builder_test.rb
93
- - test/parser_test.rb
94
- - test/resource_limits_test.rb
95
156
  - test/test_helper.rb
96
157
  homepage: http://github.com/rcode5/mojo_magick
97
158
  licenses:
@@ -113,26 +174,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
174
  requirements:
114
175
  - - ">="
115
176
  - !ruby/object:Gem::Version
116
- version: '0'
177
+ version: 2.6.0
117
178
  required_rubygems_version: !ruby/object:Gem::Requirement
118
179
  requirements:
119
180
  - - ">="
120
181
  - !ruby/object:Gem::Version
121
182
  version: '0'
122
183
  requirements: []
123
- rubyforge_project: mojo_magick
124
- rubygems_version: 2.2.2
125
- signing_key:
184
+ rubygems_version: 3.0.3
185
+ signing_key:
126
186
  specification_version: 4
127
- summary: mojo_magick-0.5.5
187
+ summary: mojo_magick-0.6.3
128
188
  test_files:
129
189
  - test/fixtures/5742.jpg
130
190
  - test/fixtures/not_an_image.jpg
191
+ - test/fixtures/roll with it.jpg
131
192
  - test/fixtures/zero_byte_image.jpg
193
+ - test/font_parser_test.rb
132
194
  - test/font_test.rb
133
- - test/fonts_test.rb
134
195
  - test/mojo_magick_test.rb
135
196
  - test/opt_builder_test.rb
136
- - test/parser_test.rb
137
- - test/resource_limits_test.rb
138
197
  - test/test_helper.rb
198
+ ...
@@ -1,96 +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
- mem_fix = 1
25
- options.each do |resource, value|
26
- @@resource_limits[resource.to_s.downcase.to_sym] = value.to_s
27
- end
28
- end
29
-
30
- # remove a limit
31
- def remove_limits(*options)
32
- mem_fix = 1
33
- @@resource_limits.delete_if do |resource, value|
34
- idx = options.index(resource)
35
- resource == options.values_at(idx)[0].to_s.downcase.to_sym if idx
36
- end
37
- end
38
-
39
- # remove limits from resources
40
- def unset_limits(options = {})
41
- mem_fix = 1
42
- @@resource_limits = {}
43
- if options[:unset_env]
44
- ENV["MAGICK_AREA_LIMIT"]=nil
45
- ENV["MAGICK_MAP_LIMIT"]=nil
46
- ENV["MAGICK_MEMORY_LIMIT"]=nil
47
- ENV["MAGICK_DISK_LIMIT"]=nil
48
- end
49
- end
50
-
51
- # returns the default limits that imagemagick is using, when run with no "-limit" parameters
52
- # options:
53
- # :show_actual_values => true (default false) - will return integers instead of readable values
54
- def get_default_limits(options = {})
55
- mem_fix = 1
56
- parse_limits(options.merge(:get_current_limits => false))
57
- end
58
-
59
- # returns the limits that imagemagick is running based on any "set_limits" calls
60
- def get_current_limits(options = {})
61
- mem_fix = 1
62
- parse_limits(options.merge(:get_current_limits => true))
63
- end
64
-
65
- alias :get_limits :get_current_limits
66
-
67
- def parse_limits(options)
68
- show_actual_values = options[:show_actual_values]
69
- if options[:get_current_limits]
70
- status = self.execute('identify', '-list resource')
71
- raw_limits = status.return_value
72
- else
73
- # we run a raw shell command here to obtain
74
- # limits without applying command line limit params
75
- raw_limits = `identify -list resource`
76
- end
77
- actual_values, readable_values = parser.parse_limits(raw_limits)
78
- show_actual_values ? actual_values : readable_values
79
- end # parse_limits
80
-
81
- # returns a string suitable for passing as a set of imagemagick params
82
- # that contains all the limit constraints
83
- def get_limits_as_params
84
- retval = ''
85
- # we upcase the value here for newer versions of ImageMagick (>=6.8.x)
86
- @@resource_limits.each do |type, value|
87
- retval += " -limit #{type.to_s} #{value.upcase} "
88
- end
89
- retval
90
- end
91
-
92
- def parser
93
- @parser ||= MojoMagick::Util::Parser.new
94
- end
95
- end
96
- end