mojo_magick 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7eb294af1589ca062245a0197a4a442f25c584fbbcbe7745d07f8976d6282c3d
4
- data.tar.gz: ddb865f0d484815352da4c5182d3674e94ec0296c1b8fb5d8579d7c461397cc1
3
+ metadata.gz: 93f3aa9373877c8a0a09828441a83f62a4f633b0779642dd881460295ec117d1
4
+ data.tar.gz: '0395757ba6b054c84b1d649333d32b6ce085eaad407a3a80e1b23054cc5a6f32'
5
5
  SHA512:
6
- metadata.gz: 00fe14025e466113053a171d7866e32cbd9c20a011efc84ca543dba8cf62ef892c9b3c96f5a4cdcf11fd524fec939f11c806687668c57c5e6df0324ff8778e03
7
- data.tar.gz: 76c39990bc119753db01f883b5592f179e2c36eb2c3f4a0f401f87ea548bfab39c9de664f6d8de4b19576a83c285a5d42fc62df25972c65d7ce8fd313e1068b4
6
+ metadata.gz: 2b417825f921e106e47a2a0387cd8dff673d468b40a95387cfbef1be8d3811067b2ee7d0115117fecaa8a39dfa77e5bec7ac9fb9fa49f8711a93df6d92e172b3
7
+ data.tar.gz: ef4726ee3b9db797d1eab003d54ebd53dba4af804583a353ae96f0299fd4f0de8dca632beb214df43bb658935166eaa66788cbbb45e102a4698a2262e76a9630
@@ -22,3 +22,4 @@ jobs:
22
22
  - run:
23
23
  name: audit
24
24
  command: bundle exec bundle-audit update && bundle exec bundle-audit check
25
+ - ruby/rubocop-check
@@ -5,6 +5,7 @@ inherit_from:
5
5
  - ./.rubocop-common.yml
6
6
  - ./.rubocop-performance.yml
7
7
 
8
- Metrics/MethodLength:
9
- Exclude:
10
- - "**/*test.rb"
8
+ Metrics/CyclomaticComplexity:
9
+ Max: 10
10
+ Metrics/PerceivedComplexity:
11
+ Max: 10
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  group :test, :development do
4
- gem 'irb', require: false
5
- gem 'simplecov', require: false
4
+ gem "irb", require: false
5
+ gem "simplecov", require: false
6
6
  end
7
7
 
8
8
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mojo_magick (0.6.2)
4
+ mojo_magick (0.6.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -139,7 +139,7 @@ complex commands.
139
139
 
140
140
  ### Get a list of available fonts
141
141
 
142
- fonts = MojoMagick::get_fonts
142
+ fonts = MojoMagick::available_fonts
143
143
 
144
144
  fonts.first
145
145
  => #<MojoMagick::Font:0x000001015a8b90 @name="AvantGarde-Book", @family="AvantGarde", @style="Normal", @stretch="Normal", @weight="400", @glyphs="/usr/local/share/ghostscript/fonts/a010013l.pfb">
@@ -211,6 +211,14 @@ in the new code
211
211
 
212
212
  Recent Changes
213
213
  ==============
214
+ #### Version 0.6.3
215
+
216
+ * Major cleanup and refactor (https://github.com/rcode5/mojo_magick/pull/33)
217
+ * Deprecated `MojoMagick.get_fonts` in favor of `MojoMagick.available_fonts`
218
+ * Moved `raw_command` and `execute` and `execute!` methods into their own module (and added deprecation warnings)
219
+ * Renamed `Util::Parser` to `Util::FontParser` because that's what it does
220
+ * Overall rubocop and ruby clean up
221
+
214
222
  #### Version 0.6.2
215
223
 
216
224
  * fix `annotate` option. Now it takes keyword arguments for geometry.
@@ -1,15 +1,8 @@
1
1
  module ImageMagick
2
- module Fonts
3
- def get_fonts
4
- @parser ||= MojoMagick::Util::Parser.new
5
- raw_fonts = begin
6
- raw_command("identify", "-list font")
7
- rescue Exception => e
8
- puts e
9
- puts "Failed to execute font list with raw_command - trying straight up execute"
10
- `convert -list font`
11
- end
12
- @parser.parse_fonts(raw_fonts)
2
+ class Fonts
3
+ def self.all
4
+ raw_fonts = MojoMagick::Commands.raw_command("identify", "-list", "font")
5
+ MojoMagick::Util::FontParser.new(raw_fonts).parse
13
6
  end
14
7
  end
15
8
  end
@@ -1,14 +1,12 @@
1
- cwd = File.dirname(__FILE__)
2
- require "open3"
3
- initializers_dir = File.expand_path(File.join(cwd, "initializers"))
4
- Dir.glob(File.join(initializers_dir, "*.rb")).sort.each { |f| require f }
5
- require File.join(cwd, "mojo_magick/util/parser")
6
- require File.join(cwd, "mojo_magick/errors")
7
- require File.join(cwd, "mojo_magick/command_status")
8
- require File.join(cwd, "image_magick/fonts")
9
- require File.join(cwd, "mojo_magick/opt_builder")
10
- require File.join(cwd, "mojo_magick/font")
11
1
  require "tempfile"
2
+ require "open3"
3
+ require_relative "./mojo_magick/util/font_parser"
4
+ require_relative "./mojo_magick/errors"
5
+ require_relative "./mojo_magick/command_status"
6
+ require_relative "./mojo_magick/commands"
7
+ require_relative "./image_magick/fonts"
8
+ require_relative "./mojo_magick/opt_builder"
9
+ require_relative "./mojo_magick/font"
12
10
 
13
11
  # MojoMagick is a stateless set of module methods which present a convient interface
14
12
  # for accessing common tasks for ImageMagick command line library.
@@ -34,7 +32,7 @@ require "tempfile"
34
32
  #
35
33
  # Equivalent to:
36
34
  #
37
- # MojoMagick::raw_command('convert', 'source.jpg -crop 250x250+0+0\
35
+ # MojoMagick::Commands.raw_command('convert', 'source.jpg -crop 250x250+0+0\
38
36
  # +repage -strip -set comment "my favorite file" dest.jpg')
39
37
  #
40
38
  # Example #mogrify usage:
@@ -43,7 +41,7 @@ require "tempfile"
43
41
  #
44
42
  # Equivalent to:
45
43
  #
46
- # MojoMagick::raw_command('mogrify', '-shave 10x10 image.jpg')
44
+ # MojoMagick::Commands.raw_command('mogrify', '-shave 10x10 image.jpg')
47
45
  #
48
46
  # Example showing some additional options:
49
47
  #
@@ -60,34 +58,40 @@ require "tempfile"
60
58
  # bang (!) can be appended to command names to use the '+' versions
61
59
  # instead of '-' versions.
62
60
  #
63
- module MojoMagick
64
- extend ImageMagick::Fonts
65
61
 
66
- def self.windows?
67
- !(RUBY_PLATFORM =~ /win32/).nil?
62
+ module MojoMagickDeprecations
63
+ # rubocop:disable Naming/AccessorMethodName
64
+ def get_fonts
65
+ warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed with the next minor version release."\
66
+ " Please use `available_fonts` instead"
67
+ MojoMagick.available_fonts
68
68
  end
69
69
 
70
- def self.execute(command, *args)
71
- execute = "#{command} #{args}"
72
- out, outerr, status = Open3.capture3(command, *args.map(&:to_s))
73
- CommandStatus.new execute, out, outerr, status
74
- rescue Exception => e
75
- raise MojoError, "#{e.class}: #{e.message}"
70
+ # rubocop:enable Naming/AccessorMethodName
71
+ ### Moved to `Commands`
72
+ def execute!(*args)
73
+ warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed with the next minor version release."\
74
+ " Please use `MojoMagick::Commands.execute!` instead"
75
+ MojoMagick::Commands.send(:execute!, *args)
76
76
  end
77
77
 
78
- def self.execute!(command, *args)
79
- status = execute(command, *args)
80
- unless status.success?
81
- err_msg = "MojoMagick command failed: #{command}."
82
- raise(MojoFailed, "#{err_msg} (Exit status: #{status.exit_code})\n" +
83
- " Command: #{status.command}\n" +
84
- " Error: #{status.error}")
85
- end
86
- status.return_value
78
+ def execute(*args)
79
+ warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed with the next minor version release."\
80
+ " Please use `MojoMagick::Commands.execute!` instead"
81
+ MojoMagick::Commands.send(:execute, *args)
82
+ end
83
+
84
+ def raw_command(*args)
85
+ warn "DEPRECATION WARNING: #{__method__} is deprecated and will be removed with the next minor version release."\
86
+ " Please use `MojoMagick::Commands.execute!` instead"
87
+ MojoMagick::Commands.raw_command(*args)
87
88
  end
89
+ end
88
90
 
89
- def self.raw_command(*args)
90
- execute!(*args)
91
+ module MojoMagick
92
+ extend MojoMagickDeprecations
93
+ def self.windows?
94
+ !RUBY_PLATFORM.include(win32)
91
95
  end
92
96
 
93
97
  def self.shrink(source_file, dest_file, options)
@@ -105,44 +109,49 @@ module MojoMagick
105
109
  # resizes an image and returns the filename written to
106
110
  # options:
107
111
  # :width / :height => scale to these dimensions
108
- # :scale => pass scale options such as ">" to force shrink scaling only or "!" to force absolute width/height scaling (do not preserve aspect ratio)
112
+ # :scale => pass scale options such as ">" to force shrink scaling only or
113
+ # "!" to force absolute width/height scaling (do not preserve aspect ratio)
109
114
  # :percent => scale image to this percentage (do not specify :width/:height in this case)
110
115
  def self.resize(source_file, dest_file, options)
111
- scale_options = []
112
- scale_options << ">" unless options[:shrink_only].nil?
113
- scale_options << "<" unless options[:expand_only].nil?
114
- scale_options << "!" unless options[:absolute_aspect].nil?
115
- scale_options << "^" unless options[:fill].nil?
116
- scale_options = scale_options.join
117
-
116
+ scale_options = extract_scale_options(options)
117
+ geometry = extract_geometry_options(options)
118
118
  extras = []
119
- if !options[:width].nil? && !options[:height].nil?
120
- geometry = "#{options[:width]}X#{options[:height]}"
121
- elsif !options[:percent].nil?
122
- geometry = "#{options[:percent]}%"
123
- else
124
- raise MojoMagickError, "Unknown options for method resize: #{options.inspect}"
125
- end
126
119
  if !options[:fill].nil? && !options[:crop].nil?
127
120
  extras << "-gravity"
128
121
  extras << "Center"
129
122
  extras << "-extent"
130
123
  extras << geometry.to_s
131
124
  end
132
- raw_command("convert",
133
- source_file,
134
- "-resize", "#{geometry}#{scale_options}",
135
- *extras, dest_file)
125
+ Commands.raw_command("convert",
126
+ source_file,
127
+ "-resize", "#{geometry}#{scale_options}",
128
+ *extras, dest_file)
136
129
  dest_file
137
130
  end
138
131
 
132
+ def self.convert(source = nil, dest = nil)
133
+ opts = OptBuilder.new
134
+ opts.file source if source
135
+ yield opts
136
+ opts.file dest if dest
137
+
138
+ Commands.raw_command("convert", *opts.to_a)
139
+ end
140
+
141
+ def self.mogrify(dest = nil)
142
+ opts = OptBuilder.new
143
+ yield opts
144
+ opts.file dest if dest
145
+ Commands.raw_command("mogrify", *opts.to_a)
146
+ end
147
+
139
148
  def self.available_fonts
140
149
  # returns width, height of image if available, nil if not
141
150
  Font.all
142
151
  end
143
152
 
144
153
  def self.get_format(source_file, format_string)
145
- raw_command("identify", "-format", format_string, source_file)
154
+ Commands.raw_command("identify", "-format", format_string, source_file)
146
155
  end
147
156
 
148
157
  # returns an empty hash or a hash with :width and :height set (e.g. {:width => INT, :height => INT})
@@ -161,22 +170,6 @@ module MojoMagick
161
170
  { width: width, height: height }
162
171
  end
163
172
 
164
- def self.convert(source = nil, dest = nil)
165
- opts = OptBuilder.new
166
- opts.file source if source
167
- yield opts
168
- opts.file dest if dest
169
-
170
- raw_command("convert", *opts.to_a)
171
- end
172
-
173
- def self.mogrify(dest = nil)
174
- opts = OptBuilder.new
175
- yield opts
176
- opts.file dest if dest
177
- raw_command("mogrify", *opts.to_a)
178
- end
179
-
180
173
  def self.tempfile(*opts)
181
174
  data = opts[0]
182
175
  rest = opts[1]
@@ -188,4 +181,27 @@ module MojoMagick
188
181
  ensure
189
182
  file.close
190
183
  end
184
+
185
+ class << self
186
+ private
187
+
188
+ def extract_geometry_options(options)
189
+ if !options[:width].nil? && !options[:height].nil?
190
+ "#{options[:width]}X#{options[:height]}"
191
+ elsif !options[:percent].nil?
192
+ "#{options[:percent]}%"
193
+ else
194
+ raise MojoMagickError, "Resize requires width and height or percentage: #{options.inspect}"
195
+ end
196
+ end
197
+
198
+ def extract_scale_options(options)
199
+ [].tap { |scale_options|
200
+ scale_options << ">" unless options[:shrink_only].nil?
201
+ scale_options << "<" unless options[:expand_only].nil?
202
+ scale_options << "!" unless options[:absolute_aspect].nil?
203
+ scale_options << "^" unless options[:fill].nil?
204
+ }.join
205
+ end
206
+ end
191
207
  end
@@ -0,0 +1,32 @@
1
+ require_relative "opt_builder"
2
+
3
+ module MojoMagick
4
+ class Commands
5
+ def self.raw_command(*args)
6
+ execute!(*args)
7
+ end
8
+
9
+ class << self
10
+ private
11
+
12
+ def execute(command, *args)
13
+ execute = "#{command} #{args}"
14
+ out, outerr, status = Open3.capture3(command, *args.map(&:to_s))
15
+ CommandStatus.new execute, out, outerr, status
16
+ rescue StandardError => e
17
+ raise MojoError, "#{e.class}: #{e.message}"
18
+ end
19
+
20
+ def execute!(command, *args)
21
+ status = execute(command, *args)
22
+ unless status.success?
23
+ err_msg = "MojoMagick command failed: #{command}."
24
+ raise(MojoFailed, "#{err_msg} (Exit status: #{status.exit_code})\n" \
25
+ " Command: #{status.command}\n" \
26
+ " Error: #{status.error}")
27
+ end
28
+ status.return_value
29
+ end
30
+ end
31
+ end
32
+ end
@@ -7,7 +7,6 @@ module MojoMagick
7
7
  end
8
8
 
9
9
  def initialize(property_hash = {})
10
- property_hash.symbolize_keys!
11
10
  %i[name family style stretch weight glyphs].each do |f|
12
11
  setter = "#{f}="
13
12
  send(setter, property_hash[f])
@@ -15,7 +14,7 @@ module MojoMagick
15
14
  end
16
15
 
17
16
  def self.all
18
- ImageMagick::Font.all.map { |font_info| Font.new(font_info) }
17
+ ImageMagick::Fonts.all
19
18
  end
20
19
  end
21
20
  end
@@ -58,6 +58,7 @@ module MojoMagick
58
58
  end
59
59
 
60
60
  # Generic commands. Arguments will be formatted if necessary
61
+ # rubocop:disable Lint/MissingSuper, Style/MissingRespondToMissing
61
62
  def method_missing(command, *args)
62
63
  @opts << if command.to_s[-1, 1] == "!"
63
64
  "+#{command.to_s.chop}"
@@ -68,10 +69,7 @@ module MojoMagick
68
69
  self
69
70
  end
70
71
 
71
- def to_s
72
- to_a.join " "
73
- end
74
-
72
+ # rubocop:enable Lint/MissingSuper, Style/MissingRespondToMissing
75
73
  def to_a
76
74
  @opts.flatten
77
75
  end
@@ -0,0 +1,43 @@
1
+ # rubocop:disable Lint/AssignmentInCondition
2
+ module MojoMagick
3
+ module Util
4
+ class FontParser
5
+ attr_reader :raw_fonts
6
+
7
+ def initialize(raw_fonts)
8
+ @raw_fonts = raw_fonts
9
+ end
10
+
11
+ def parse
12
+ fonts = {}
13
+ enumerator = raw_fonts.split(/\n/).each
14
+ name = nil
15
+ while begin; line = enumerator.next; rescue StopIteration; line = nil; end
16
+ line.chomp!
17
+ line = enumerator.next if line_is_empty(line)
18
+ m = /^\s*Font:\s+(.*)$/.match(line)
19
+ if m
20
+ name = m[1].strip
21
+ fonts[name] = { name: name }
22
+ else
23
+ k, v = extract_key_value(line)
24
+ fonts[name][k] = v if k && name
25
+ end
26
+ end
27
+ fonts.values.map { |f| MojoMagick::Font.new f }
28
+ end
29
+
30
+ private
31
+
32
+ def extract_key_value(line)
33
+ key_val = line.split(/:/).map(&:strip)
34
+ [key_val[0].downcase.to_sym, key_val[1]]
35
+ end
36
+
37
+ def line_is_empty(line)
38
+ line.nil? || line.empty? || (/^\s+$/ =~ line)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ # rubocop:enable Lint/AssignmentInCondition
@@ -1,28 +1,20 @@
1
- # rubocop:disable Lint/AssignmentInCondition
1
+ require_relative "./font_parser"
2
2
  module MojoMagick
3
3
  module Util
4
4
  class Parser
5
- # handle parsing outputs from ImageMagick commands
5
+ attr_reader :raw_fonts
6
6
 
7
- def parse_fonts(raw_fonts)
8
- fonts = {}
9
- enumerator = raw_fonts.split(/\n/).each
10
- name = nil
11
- while begin; line = enumerator.next; rescue StopIteration; line = nil; end
12
- line.chomp!
13
- line = enumerator.next if line.nil? || line.empty? || (/^\s+$/ =~ line)
14
- m = /^\s*Font:\s+(.*)$/.match(line)
15
- if m
16
- name = m[1].strip
17
- fonts[name] = { name: name }
18
- else
19
- key_val = line.split(/:/).map(&:strip)
20
- k = key_val[0].downcase.to_sym
21
- v = key_val[1]
22
- fonts[name][k] = v if k && name
23
- end
24
- end
25
- fonts.values.map { |f| MojoMagick::Font.new f }
7
+ def initialize
8
+ warn "DEPRECATION WARNING: This class has been deprecated and will be removed with"\
9
+ " the next minor version release."\
10
+ " Please use `MojoMagick::Util::FontParser` instead"
11
+ end
12
+
13
+ def parse_fonts(fonts)
14
+ warn "DEPRECATION WARNING: #{__method__} has been deprecated and will be removed with"\
15
+ " the next minor version release."\
16
+ " Please use `MojoMagick::Util::FontParser#parse` instead"
17
+ FontParser.new(fonts).parse
26
18
  end
27
19
  end
28
20
  end
@@ -1,3 +1,3 @@
1
1
  module MojoMagick
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -30,8 +30,8 @@ Gem::Specification.new do |s|
30
30
  s.test_files = `git ls-files -- {test,features}/*`.split("\n")
31
31
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
32
32
  s.require_paths = ["lib"]
33
- s.add_development_dependency("bundler")
34
33
  s.add_development_dependency("bundle-audit")
34
+ s.add_development_dependency("bundler")
35
35
  s.add_development_dependency("minitest")
36
36
  s.add_development_dependency("rake")
37
37
  s.add_development_dependency("rspec-expectations")
@@ -19,10 +19,10 @@ IDENTIFY_FONT_RESPONSE = <<~EOFONT
19
19
 
20
20
  EOFONT
21
21
 
22
- class ParserTest < MiniTest::Test
22
+ class FontParserTest < MiniTest::Test
23
23
  def test_parse_fonts
24
- parser = MojoMagick::Util::Parser.new
25
- parsed_fonts = parser.parse_fonts(IDENTIFY_FONT_RESPONSE)
24
+ parser = MojoMagick::Util::FontParser.new(IDENTIFY_FONT_RESPONSE)
25
+ parsed_fonts = parser.parse
26
26
  assert_equal parsed_fonts.length, 2
27
27
  assert_equal parsed_fonts[1].style, "Italic"
28
28
  end
@@ -6,6 +6,11 @@ class MojoMagickTest < MiniTest::Test
6
6
  def setup
7
7
  @fixtures_path = File.expand_path(File.join(File.dirname(__FILE__), "fixtures"))
8
8
  @working_path = File.join(@fixtures_path, "tmp")
9
+
10
+ reset_images
11
+
12
+ @test_image = File.join(@working_path, "5742.jpg")
13
+ @out_image = File.join(@working_path, "out1.jpg")
9
14
  end
10
15
 
11
16
  def reset_images
@@ -14,11 +19,9 @@ class MojoMagickTest < MiniTest::Test
14
19
  Dir.glob(File.join(@fixtures_path, "*")).each do |file|
15
20
  FileUtils.cp(file, @working_path) if File.file?(file)
16
21
  end
17
- @test_image = File.join(@working_path, "5742.jpg")
18
22
  end
19
23
 
20
24
  def test_get_image_size
21
- reset_images
22
25
  orig_image_size = File.size(@test_image)
23
26
  retval = MojoMagick.get_image_size(@test_image)
24
27
  assert_equal orig_image_size, File.size(@test_image)
@@ -28,7 +31,6 @@ class MojoMagickTest < MiniTest::Test
28
31
 
29
32
  def test_image_resize
30
33
  # test basic resizing
31
- reset_images
32
34
  orig_image_size = File.size(@test_image)
33
35
  size_test_temp = Tempfile.new("mojo_test")
34
36
  size_test = size_test_temp.path
@@ -41,16 +43,15 @@ class MojoMagickTest < MiniTest::Test
41
43
  assert_equal 67, new_dimensions[:width]
42
44
 
43
45
  # we should be able to resize image right over itself
44
- retval = MojoMagick.resize(@test_image, @test_image, { width: 100, height: 100 })
46
+ retval = MojoMagick.resize(@test_image, @test_image, { width: 150, height: 150 })
45
47
  assert_equal @test_image, retval
46
48
  refute_equal orig_image_size, File.size(@test_image)
47
49
  new_dimensions = MojoMagick.get_image_size(@test_image)
48
- assert_equal 100, new_dimensions[:height]
49
- assert_equal 67, new_dimensions[:width]
50
+ assert_equal 150, new_dimensions[:height]
51
+ assert_equal 100, new_dimensions[:width]
50
52
  end
51
53
 
52
54
  def test_image_resize_with_percentage
53
- reset_images
54
55
  original_size = MojoMagick.get_image_size(@test_image)
55
56
  retval = MojoMagick.resize(@test_image, @test_image, { percent: 50 })
56
57
  assert_equal @test_image, retval
@@ -62,7 +63,6 @@ class MojoMagickTest < MiniTest::Test
62
63
 
63
64
  def test_shrink_with_big_dimensions
64
65
  # image shouldn't resize if we specify very large dimensions and specify "shrink_only"
65
- reset_images
66
66
  size_test_temp = Tempfile.new("mojo_test")
67
67
  size_test = size_test_temp.path
68
68
  retval = MojoMagick.shrink(@test_image, size_test, { width: 1000, height: 1000 })
@@ -73,7 +73,6 @@ class MojoMagickTest < MiniTest::Test
73
73
  end
74
74
 
75
75
  def test_shrink
76
- reset_images
77
76
  # image should resize if we specify small dimensions and shrink_only
78
77
  retval = MojoMagick.shrink(@test_image, @test_image, { width: 1000, height: 100 })
79
78
  assert_equal @test_image, retval
@@ -83,7 +82,6 @@ class MojoMagickTest < MiniTest::Test
83
82
  end
84
83
 
85
84
  def test_resize_with_shrink_only_options
86
- reset_images
87
85
  # image should resize if we specify small dimensions and shrink_only
88
86
  retval = MojoMagick.resize(@test_image, @test_image, { shrink_only: true, width: 400, height: 400 })
89
87
  assert_equal @test_image, retval
@@ -94,7 +92,6 @@ class MojoMagickTest < MiniTest::Test
94
92
 
95
93
  def test_expand_with_small_dim
96
94
  # image shouldn't resize if we specify small dimensions and expand_only
97
- reset_images
98
95
  _orig_image_size = File.size(@test_image)
99
96
  retval = MojoMagick.expand(@test_image, @test_image, { width: 10, height: 10 })
100
97
  assert_equal @test_image, retval
@@ -104,7 +101,6 @@ class MojoMagickTest < MiniTest::Test
104
101
  end
105
102
 
106
103
  def test_expand
107
- reset_images
108
104
  # image should resize if we specify large dimensions and expand_only
109
105
  retval = MojoMagick.expand(@test_image, @test_image, { width: 1000, height: 1000 })
110
106
  assert_equal @test_image, retval
@@ -125,7 +121,6 @@ class MojoMagickTest < MiniTest::Test
125
121
  end
126
122
 
127
123
  def test_resize_with_fill
128
- reset_images
129
124
  @test_image = File.join(@working_path, "5742.jpg")
130
125
  MojoMagick.resize(@test_image, @test_image, { fill: true, width: 100, height: 100 })
131
126
  dim = MojoMagick.get_image_size(@test_image)
@@ -134,7 +129,6 @@ class MojoMagickTest < MiniTest::Test
134
129
  end
135
130
 
136
131
  def test_resize_with_fill_and_crop
137
- reset_images
138
132
  @test_image = File.join(@working_path, "5742.jpg")
139
133
  MojoMagick.resize(@test_image, @test_image, { fill: true, crop: true, width: 150, height: 120 })
140
134
  dim = MojoMagick.get_image_size(@test_image)
@@ -151,7 +145,6 @@ class MojoMagickTest < MiniTest::Test
151
145
  end
152
146
 
153
147
  def test_label
154
- reset_images
155
148
  out_image = File.join(@working_path, "label_test.png")
156
149
 
157
150
  MojoMagick.convert do |c|
@@ -161,7 +154,6 @@ class MojoMagickTest < MiniTest::Test
161
154
  end
162
155
 
163
156
  def test_label_with_quote
164
- reset_images
165
157
  out_image = File.join(@working_path, "label_test.png")
166
158
 
167
159
  MojoMagick.convert do |c|
@@ -171,7 +163,6 @@ class MojoMagickTest < MiniTest::Test
171
163
  end
172
164
 
173
165
  def test_label_with_apostrophe
174
- reset_images
175
166
  out_image = File.join(@working_path, "label_test.png")
176
167
 
177
168
  MojoMagick.convert do |c|
@@ -181,7 +172,6 @@ class MojoMagickTest < MiniTest::Test
181
172
  end
182
173
 
183
174
  def test_label_with_quotes
184
- reset_images
185
175
  out_image = File.join(@working_path, "label_test.png")
186
176
 
187
177
  MojoMagick.convert do |c|
@@ -202,10 +192,7 @@ class MojoMagickTest < MiniTest::Test
202
192
  "Unable to find ImageMagick commandline error in the message"
203
193
  end
204
194
 
205
- def test_blob
206
- reset_images
207
-
208
- # RGB8 test
195
+ def test_blob_rgb
209
196
  data = (Array.new(16) { [rand > 0.5 ? 0 : 255] * 3 }).flatten
210
197
  bdata = data.pack "C" * data.size
211
198
  out = "out.png"
@@ -217,48 +204,57 @@ class MojoMagickTest < MiniTest::Test
217
204
  assert r[:width] == 4
218
205
  end
219
206
 
220
- def test_command_helpers
221
- reset_images
222
- test_image = File.join(@working_path, "5742.jpg")
223
- out_image = File.join(@working_path, "out1.jpg")
224
-
225
- # Simple convert test
207
+ def test_convert
226
208
  MojoMagick.convert do |c|
227
- c.file test_image
209
+ c.file @test_image
228
210
  c.crop "92x64+0+0"
229
211
  c.repage!
230
- c.file out_image
212
+ c.file @out_image
231
213
  end
232
- retval = MojoMagick.get_image_size(out_image)
214
+ retval = MojoMagick.get_image_size(@out_image)
233
215
  assert_equal 92, retval[:width]
234
216
  assert_equal 64, retval[:height]
217
+ end
235
218
 
219
+ def test_mogrify
220
+ MojoMagick.convert do |c|
221
+ c.file @test_image
222
+ c.file @out_image
223
+ end
236
224
  # Simple mogrify test
237
225
  MojoMagick.mogrify do |m|
238
226
  m.crop "32x32+0+0"
239
227
  m.repage!
240
- m.file out_image
228
+ m.file @out_image
241
229
  end
242
- retval = MojoMagick.get_image_size(out_image)
230
+ retval = MojoMagick.get_image_size(@out_image)
243
231
  assert_equal 32, retval[:width]
244
232
  assert_equal 32, retval[:height]
233
+ end
245
234
 
246
- # Convert test, using file shortcuts
247
- MojoMagick.convert(test_image, out_image) do |c|
235
+ def test_convert_crop_and_repage
236
+ MojoMagick.convert(@test_image, @out_image) do |c|
248
237
  c.crop "100x100+0+0"
249
238
  c.repage!
250
239
  end
251
- retval = MojoMagick.get_image_size(out_image)
240
+ retval = MojoMagick.get_image_size(@out_image)
252
241
  assert_equal 100, retval[:width]
253
242
  assert_equal 100, retval[:height]
243
+ end
254
244
 
255
- # Mogrify test, using file shortcut
256
- MojoMagick.mogrify(out_image) { |m| m.shave("25x25").repage! }
257
- retval = MojoMagick.get_image_size(out_image)
245
+ def test_mogrify_with_shave_and_repage
246
+ MojoMagick.convert do |c|
247
+ c.file @test_image
248
+ c.crop "100x100+0+0"
249
+ c.file @out_image
250
+ end
251
+ MojoMagick.mogrify(@out_image) { |m| m.shave("25x25").repage! }
252
+ retval = MojoMagick.get_image_size(@out_image)
258
253
  assert_equal 50, retval[:width]
259
254
  assert_equal 50, retval[:height]
255
+ end
260
256
 
261
- # RGB8 test
257
+ def test_convert_rgb
262
258
  bdata = "aaaaaabbbbbbccc"
263
259
  out = "out.png"
264
260
  MojoMagick.convert do |c|
@@ -268,7 +264,9 @@ class MojoMagickTest < MiniTest::Test
268
264
  r = MojoMagick.get_image_size(out)
269
265
  assert r[:height] == 1
270
266
  assert r[:width] == 5
267
+ end
271
268
 
269
+ def test_convert_rgba
272
270
  bdata = "1111222233334444"
273
271
  out = "out.png"
274
272
  MojoMagick.convert do |c|
@@ -279,4 +277,12 @@ class MojoMagickTest < MiniTest::Test
279
277
  assert r[:height] == 1
280
278
  assert r[:width] == 4
281
279
  end
280
+
281
+ def test_available_fonts
282
+ fonts = MojoMagick.available_fonts
283
+ assert fonts.is_a? Array
284
+ assert fonts.length > 1
285
+ assert fonts.first.name
286
+ assert(fonts.first.name.is_a?(String))
287
+ end
282
288
  end
@@ -19,12 +19,12 @@ class MojoMagickOptBuilderTest < MiniTest::Test
19
19
  assert_equal %w[-annotate 0 it's], @builder.to_a
20
20
  end
21
21
 
22
- def test_annotate_with_full_args
22
+ def test_annotate_with_multiple_args
23
23
  @builder.annotate "5 it's"
24
- assert_equal %w[-annotate 5 it's], @builder.to_a
24
+ assert_equal ["-annotate", "0", "5 it's"], @builder.to_a
25
25
  end
26
26
 
27
- def test_annotate_with_full_args
27
+ def test_annotate_with_geometry_args
28
28
  @builder.annotate "this thing", geometry: 3
29
29
  assert_equal ["-annotate", "3", "this thing"], @builder.to_a
30
30
  end
@@ -36,95 +36,104 @@ class MojoMagickOptBuilderTest < MiniTest::Test
36
36
 
37
37
  def test_option_builder_with_blocks
38
38
  # Passing in basic commands produces a string
39
- b = MojoMagick::OptBuilder.new
40
- b.image_block do
41
- b.background "red"
39
+ @builder.image_block do
40
+ @builder.background "red"
42
41
  end
43
- b.image_block do
44
- b.background "blue"
42
+ @builder.image_block do
43
+ @builder.background "blue"
45
44
  end
46
- assert_equal ['\(', "-background", "red", '\)', '\(', "-background", "blue", '\)'], b.to_a
45
+ assert_equal ['\(', "-background", "red", '\)', '\(', "-background", "blue", '\)'], @builder.to_a
47
46
  end
48
47
 
49
48
  def test_option_builder_with_hex_colors
50
- b = MojoMagick::OptBuilder.new
51
- b.background "#000000"
52
- assert_equal %w[-background #000000], b.to_a
49
+ @builder.background "#000000"
50
+ assert_equal %w[-background #000000], @builder.to_a
53
51
  end
54
52
 
55
53
  def test_option_builder
56
- # Passing in basic commands produces a string
57
- b = MojoMagick::OptBuilder.new
58
- b.strip
59
- b.repage
60
- assert_equal "-strip -repage", b.to_s
54
+ @builder.strip
55
+ @builder.repage
56
+ assert_equal %w[-strip -repage], @builder.to_a
57
+ end
61
58
 
62
- # Chaining commands works
63
- b = MojoMagick::OptBuilder.new.strip.repage
64
- 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
65
62
 
63
+ def test_opt_builder_interpreting_bang_suffix
66
64
  # Bang (!) indicates the plus version of commands
67
- b = MojoMagick::OptBuilder.new
68
- b.repage
69
- b.repage!
70
- assert_equal "-repage +repage", b.to_s
71
65
 
72
- # Accepts raw data as-is
73
- b = MojoMagick::OptBuilder.new
74
- b.opt1
75
- b << "a ! b !"
76
- b.opt2
77
- 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
78
70
 
71
+ def test_opt_builder_pushing_raw_data
79
72
  # Treats an array of raw data as different arguments
80
- b = MojoMagick::OptBuilder.new
81
- b << ["leave this data", "alone"]
82
- assert_equal "leave this data alone", b.to_s
83
-
84
- # String includes command arguments
85
- b = MojoMagick::OptBuilder.new
86
- b.extent "256x256+0+0"
87
- b.crop "64x64"
88
- assert_equal %w[-extent 256x256+0+0 -crop 64x64], b.to_a
89
-
90
- # Arguments are quoted (doublequote) if appropriate
91
- b = MojoMagick::OptBuilder.new
92
- b.comment "white space"
93
- b.comment "w&b"
94
- b.crop "6x6^"
95
- assert_equal ["-comment", "white space", "-comment", "w&b", "-crop", "6x6^"], b.to_a
96
-
97
- # Existing doublequotes are escaped
98
- b = MojoMagick::OptBuilder.new
99
- b.comment 'Fred "Woot" Rook'
100
- assert_equal ["-comment", "Fred \"Woot\" Rook"], b.to_a
101
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
102
85
  # Multi-argument commands should not be quoted together
103
- b = MojoMagick::OptBuilder.new
104
- b.set "comment", 'the "best" comment'
105
- assert_equal ["-set", "comment", "the \"best\" comment"], b.to_a
106
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
107
101
  # File and files are helper methods
108
- b = MojoMagick::OptBuilder.new
109
- b.files "source.jpg", "source2.jpg"
110
- b.append
111
- b.crop "64x64"
112
- b.file "dest%d.jpg"
113
- assert_equal %w[source.jpg source2.jpg -append -crop 64x64 dest%d.jpg], b.to_a
114
-
115
- # Files are quoted (doublequote) if appropriate
116
- b = MojoMagick::OptBuilder.new
117
- b.file "probably on windows.jpg"
118
- assert_equal ["probably on windows.jpg"], b.to_a
119
-
120
- # Blob is a shortcut for the #tempfile helper method
121
- b = MojoMagick::OptBuilder.new
122
- b.blob "binary data"
123
- filename = b.to_s
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
124
131
  File.open(filename, "rb") do |f|
125
132
  assert_equal "binary data", f.read
126
133
  end
134
+ end
127
135
 
136
+ def test_opt_builder_label
128
137
  # label for text should use 'label:"the string"' if specified
129
138
  [%w[mylabel mylabel],
130
139
  ['my " label', '"my \" label"'],
@@ -133,7 +142,7 @@ class MojoMagickOptBuilderTest < MiniTest::Test
133
142
  ["\#$%^&*", '"#$%^&*"']].each do |labels|
134
143
  b = MojoMagick::OptBuilder.new
135
144
  b.label labels[0]
136
- assert_equal "label:#{labels[1]}", b.to_s
145
+ assert_equal ["label:#{labels[1]}"], b.to_a
137
146
  end
138
147
  end
139
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojo_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Midgley
@@ -10,10 +10,10 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-01-23 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: bundler
16
+ name: bundle-audit
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
@@ -27,7 +27,7 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
- name: bundle-audit
30
+ name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
@@ -135,12 +135,13 @@ files:
135
135
  - examples/composite.rb
136
136
  - init.rb
137
137
  - lib/image_magick/fonts.rb
138
- - lib/initializers/hash.rb
139
138
  - lib/mojo_magick.rb
140
139
  - lib/mojo_magick/command_status.rb
140
+ - lib/mojo_magick/commands.rb
141
141
  - lib/mojo_magick/errors.rb
142
142
  - lib/mojo_magick/font.rb
143
143
  - lib/mojo_magick/opt_builder.rb
144
+ - lib/mojo_magick/util/font_parser.rb
144
145
  - lib/mojo_magick/util/parser.rb
145
146
  - lib/mojo_magick/version.rb
146
147
  - mojo_magick.gemspec
@@ -148,11 +149,10 @@ files:
148
149
  - test/fixtures/not_an_image.jpg
149
150
  - test/fixtures/roll with it.jpg
150
151
  - test/fixtures/zero_byte_image.jpg
152
+ - test/font_parser_test.rb
151
153
  - test/font_test.rb
152
- - test/fonts_test.rb
153
154
  - test/mojo_magick_test.rb
154
155
  - test/opt_builder_test.rb
155
- - test/parser_test.rb
156
156
  - test/test_helper.rb
157
157
  homepage: http://github.com/rcode5/mojo_magick
158
158
  licenses:
@@ -184,16 +184,15 @@ requirements: []
184
184
  rubygems_version: 3.0.3
185
185
  signing_key:
186
186
  specification_version: 4
187
- summary: mojo_magick-0.6.2
187
+ summary: mojo_magick-0.6.3
188
188
  test_files:
189
189
  - test/fixtures/5742.jpg
190
190
  - test/fixtures/not_an_image.jpg
191
191
  - test/fixtures/roll with it.jpg
192
192
  - test/fixtures/zero_byte_image.jpg
193
+ - test/font_parser_test.rb
193
194
  - test/font_test.rb
194
- - test/fonts_test.rb
195
195
  - test/mojo_magick_test.rb
196
196
  - test/opt_builder_test.rb
197
- - test/parser_test.rb
198
197
  - test/test_helper.rb
199
198
  ...
@@ -1,12 +0,0 @@
1
- class Hash
2
- def symbolize_keys!
3
- keys.each do |key|
4
- self[begin
5
- key.to_sym
6
- rescue StandardError
7
- key
8
- end || key] = delete(key)
9
- end
10
- self
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- require_relative "test_helper"
2
-
3
- class FontsTest < MiniTest::Test
4
- def test_get_fonts
5
- fonts = MojoMagick.get_fonts
6
- assert fonts.is_a? Array
7
- assert fonts.length > 1
8
- assert fonts.first.name
9
- assert(fonts.first.name.is_a?(String))
10
- end
11
- end