mojo_magick 0.5.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,10 @@ class Hash
2
2
  def symbolize_keys!
3
3
  keys.each do |key|
4
4
  self[begin
5
- key.to_sym
6
- rescue StandardError
7
- key
8
- end || key] = delete(key)
5
+ key.to_sym
6
+ rescue StandardError
7
+ key
8
+ end || key] = delete(key)
9
9
  end
10
10
  self
11
11
  end
@@ -1,15 +1,14 @@
1
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')).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/resource_limits')
9
- require File.join(cwd, 'image_magick/fonts')
10
- require File.join(cwd, 'mojo_magick/opt_builder')
11
- require File.join(cwd, 'mojo_magick/font')
12
- require 'tempfile'
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
+ require "tempfile"
13
12
 
14
13
  # MojoMagick is a stateless set of module methods which present a convient interface
15
14
  # for accessing common tasks for ImageMagick command line library.
@@ -35,7 +34,8 @@ require 'tempfile'
35
34
  #
36
35
  # Equivalent to:
37
36
  #
38
- # MojoMagick::raw_command('convert', 'source.jpg -crop 250x250+0+0 +repage -strip -set comment "my favorite file" dest.jpg')
37
+ # MojoMagick::raw_command('convert', 'source.jpg -crop 250x250+0+0\
38
+ # +repage -strip -set comment "my favorite file" dest.jpg')
39
39
  #
40
40
  # Example #mogrify usage:
41
41
  #
@@ -61,32 +61,27 @@ require 'tempfile'
61
61
  # instead of '-' versions.
62
62
  #
63
63
  module MojoMagick
64
- # enable resource limiting functionality
65
- extend ImageMagick::ResourceLimits
66
64
  extend ImageMagick::Fonts
67
65
 
68
66
  def self.windows?
69
67
  !(RUBY_PLATFORM =~ /win32/).nil?
70
68
  end
71
69
 
72
- def self.execute(command, args, _options = {})
73
- # this suppress error messages to the console
74
- # err_pipe = windows? ? "2>nul" : "2>/dev/null"
75
-
76
- execute = "#{command} #{get_limits_as_params} #{args}"
77
- out, outerr, status = Open3.capture3(execute)
70
+ def self.execute(command, *args)
71
+ execute = "#{command} #{args}"
72
+ out, outerr, status = Open3.capture3(command, *args.map(&:to_s))
78
73
  CommandStatus.new execute, out, outerr, status
79
74
  rescue Exception => e
80
75
  raise MojoError, "#{e.class}: #{e.message}"
81
76
  end
82
77
 
83
- def self.execute!(command, args, options = {})
84
- # this suppress error messages to the console
85
- # err_pipe = windows? ? "2>nul" : "2>/dev/null"
86
- status = execute(command, args, options)
78
+ def self.execute!(command, *args)
79
+ status = execute(command, *args)
87
80
  unless status.success?
88
- err_msg = options[:err_msg] || "MojoMagick command failed: #{command}."
89
- raise(MojoFailed, "#{err_msg} (Exit status: #{status.exit_code})\n Command: #{status.command}\n Error: #{status.error}")
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}")
90
85
  end
91
86
  status.return_value
92
87
  end
@@ -114,10 +109,10 @@ module MojoMagick
114
109
  # :percent => scale image to this percentage (do not specify :width/:height in this case)
115
110
  def self.resize(source_file, dest_file, options)
116
111
  scale_options = []
117
- scale_options << '>' unless options[:shrink_only].nil?
118
- scale_options << '<' unless options[:expand_only].nil?
119
- scale_options << '!' unless options[:absolute_aspect].nil?
120
- scale_options << '^' unless options[:fill].nil?
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?
121
116
  scale_options = scale_options.join
122
117
 
123
118
  extras = []
@@ -129,10 +124,15 @@ module MojoMagick
129
124
  raise MojoMagickError, "Unknown options for method resize: #{options.inspect}"
130
125
  end
131
126
  if !options[:fill].nil? && !options[:crop].nil?
132
- extras << '-gravity Center'
133
- extras << "-extent #{geometry}"
127
+ extras << "-gravity"
128
+ extras << "Center"
129
+ extras << "-extent"
130
+ extras << geometry.to_s
134
131
  end
135
- raw_command('convert', "\"#{source_file}\" -resize \"#{geometry}#{scale_options}\" #{extras.join(' ')} \"#{dest_file}\"")
132
+ raw_command("convert",
133
+ source_file,
134
+ "-resize", "#{geometry}#{scale_options}",
135
+ *extras, dest_file)
136
136
  dest_file
137
137
  end
138
138
 
@@ -142,14 +142,14 @@ module MojoMagick
142
142
  end
143
143
 
144
144
  def self.get_format(source_file, format_string)
145
- raw_command('identify', "-format \"#{format_string}\" \"#{source_file}\"")
145
+ raw_command("identify", "-format", format_string, source_file)
146
146
  end
147
147
 
148
148
  # returns an empty hash or a hash with :width and :height set (e.g. {:width => INT, :height => INT})
149
149
  # raises MojoFailed when results are indeterminate (width and height could not be determined)
150
150
  def self.get_image_size(source_file)
151
151
  # returns width, height of image if available, nil if not
152
- retval = get_format(source_file, 'w:%w h:%h')
152
+ retval = get_format(source_file, "w:%w h:%h")
153
153
  return {} unless retval
154
154
 
155
155
  width = retval.match(/w:([0-9]+) /)
@@ -166,25 +166,26 @@ module MojoMagick
166
166
  opts.file source if source
167
167
  yield opts
168
168
  opts.file dest if dest
169
- raw_command('convert', opts.to_s)
169
+
170
+ raw_command("convert", *opts.to_a)
170
171
  end
171
172
 
172
173
  def self.mogrify(dest = nil)
173
174
  opts = OptBuilder.new
174
175
  yield opts
175
176
  opts.file dest if dest
176
- raw_command('mogrify', opts.to_s)
177
+ raw_command("mogrify", *opts.to_a)
177
178
  end
178
179
 
179
180
  def self.tempfile(*opts)
180
181
  data = opts[0]
181
182
  rest = opts[1]
182
183
  ext = rest && rest[:format]
183
- file = Tempfile.new(['mojo', ext ? '.' + ext.to_s : ''])
184
+ file = Tempfile.new(["mojo", ext ? ".#{ext}" : ""])
184
185
  file.binmode
185
186
  file.write(data)
186
187
  file.path
187
188
  ensure
188
189
  file.close
189
190
  end
190
- end # MojoMagick
191
+ end
@@ -5,7 +5,7 @@ module MojoMagick
5
5
  end
6
6
 
7
7
  def exit_code
8
- system_status.exitstatus || 'unknown'
8
+ system_status.exitstatus || "unknown"
9
9
  end
10
10
  end
11
11
  end
@@ -17,9 +17,7 @@ module MojoMagick
17
17
 
18
18
  # Add files to command line, formatted if necessary
19
19
  def file(*args)
20
- args.each do |arg|
21
- add_formatted arg
22
- end
20
+ @opts << args
23
21
  self
24
22
  end
25
23
  alias files file
@@ -30,20 +28,16 @@ module MojoMagick
30
28
 
31
29
  # annotate takes non-standard args
32
30
  def annotate(*args)
33
- @opts << '-annotate'
31
+ @opts << "-annotate"
34
32
  arguments = args.join.split
35
- arguments.unshift '0' if arguments.length == 1
36
- arguments.each do |arg|
37
- add_formatted arg
38
- end
33
+ arguments.unshift "0" if arguments.length == 1
34
+ @opts << arguments
39
35
  end
40
36
 
41
37
  # Create a temporary file for the given image and add to command line
42
38
  def format(*args)
43
- @opts << '-format'
44
- args.each do |arg|
45
- add_formatted arg
46
- end
39
+ @opts << "-format"
40
+ @opts << args
47
41
  end
48
42
 
49
43
  def blob(*args)
@@ -65,32 +59,29 @@ module MojoMagick
65
59
 
66
60
  # Generic commands. Arguments will be formatted if necessary
67
61
  def method_missing(command, *args)
68
- @opts << if command.to_s[-1, 1] == '!'
62
+ @opts << if command.to_s[-1, 1] == "!"
69
63
  "+#{command.to_s.chop}"
70
64
  else
71
65
  "-#{command}"
72
66
  end
73
- args.each do |arg|
74
- add_formatted arg
75
- end
67
+ @opts << args
76
68
  self
77
69
  end
78
70
 
79
71
  def to_s
80
- @opts.join ' '
72
+ to_a.join " "
81
73
  end
82
74
 
83
- protected
84
-
85
- def add_formatted(arg)
86
- # Quote anything that would cause problems on *nix or windows
87
- @opts << quoted_arg(arg)
75
+ def to_a
76
+ @opts.flatten
88
77
  end
89
78
 
79
+ protected
80
+
90
81
  def quoted_arg(arg)
91
- return arg unless arg =~ /[#'<>^|&();` ]/
82
+ return arg unless /[#'<>^|&();` ]/.match?(arg)
92
83
 
93
- ['"', arg.gsub('"', '\"').gsub("'", "\'"), '"'].join
84
+ ['"', arg.gsub('"', '\"').tr("'", "\'"), '"'].join
94
85
  end
95
86
  end
96
87
  end
@@ -1,3 +1,4 @@
1
+ # rubocop:disable Lint/AssignmentInCondition
1
2
  module MojoMagick
2
3
  module Util
3
4
  class Parser
@@ -10,9 +11,10 @@ module MojoMagick
10
11
  while begin; line = enumerator.next; rescue StopIteration; line = nil; end
11
12
  line.chomp!
12
13
  line = enumerator.next if line.nil? || line.empty? || (/^\s+$/ =~ line)
13
- if m = /^\s*Font:\s+(.*)$/.match(line)
14
+ m = /^\s*Font:\s+(.*)$/.match(line)
15
+ if m
14
16
  name = m[1].strip
15
- fonts[name] = {name: name}
17
+ fonts[name] = { name: name }
16
18
  else
17
19
  key_val = line.split(/:/).map(&:strip)
18
20
  k = key_val[0].downcase.to_sym
@@ -20,46 +22,7 @@ module MojoMagick
20
22
  fonts[name][k] = v if k && name
21
23
  end
22
24
  end
23
- fonts.values.map { |f| MojoMagick::Font.new f}
24
- end
25
-
26
- def parse_limits(raw_limits)
27
- row_limits = raw_limits.split("\n")
28
- header = row_limits[0].chomp
29
- data = row_limits[2].chomp
30
- resources = header.strip.split
31
- limits = data.strip.split
32
-
33
- actual_values = {}
34
- readable_values = {}
35
-
36
- resources.each_index do |i|
37
- resource = resources[i].downcase.to_sym
38
- scale = limits[i].match(/[a-z]+$/) || []
39
- value = limits[i].match(/^[0-9]+/)
40
- unscaled_value = value ? value[0].to_i : -1
41
- scaled_value = case scale[0]
42
- when 'eb'
43
- unscaled_value * (2**60)
44
- when 'pb'
45
- unscaled_value * (2**50)
46
- when 'tb'
47
- unscaled_value * (2**40)
48
- when 'gb'
49
- unscaled_value * (2**30)
50
- when 'mb'
51
- unscaled_value * (2**20)
52
- when 'kb'
53
- unscaled_value * (2**10)
54
- when 'b'
55
- unscaled_value
56
- else
57
- unscaled_value
58
- end
59
- actual_values[resource] = scaled_value
60
- readable_values[resource] = limits[i]
61
- end
62
- [actual_values, readable_values]
25
+ fonts.values.map { |f| MojoMagick::Font.new f }
63
26
  end
64
27
  end
65
28
  end
@@ -1,3 +1,3 @@
1
1
  module MojoMagick
2
- VERSION = '0.5.7'.freeze
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,7 +1,7 @@
1
- $:.push File.expand_path('lib', __dir__)
2
- require 'mojo_magick/version'
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
+ require "mojo_magick/version"
3
3
 
4
- post_install_message = <<~EOF
4
+ post_install_message = <<~EOPOST_INSTALL
5
5
 
6
6
  Thanks for installing MojoMagick - keepin it simple!
7
7
 
@@ -10,29 +10,33 @@ post_install_message = <<~EOF
10
10
  If you plan to build images with text (using the "label" method) you'll need freetype and ghostscript as well.
11
11
  Check out http://www.freetype.org and http://ghostscript.com respectively for installation info.
12
12
 
13
- EOF
13
+ EOPOST_INSTALL
14
14
 
15
15
  Gem::Specification.new do |s|
16
- s.name = 'mojo_magick'
17
- s.license = 'MIT'
16
+ s.name = "mojo_magick"
17
+ s.license = "MIT"
18
18
  s.version = MojoMagick::VERSION
19
19
  s.platform = Gem::Platform::RUBY
20
- s.authors = ['Steve Midgley', 'Elliot Nelson', 'Jon Rogers']
21
- s.email = ['science@misuse.org', 'jon@rcode5.com']
22
- s.homepage = 'http://github.com/rcode5/mojo_magick'
20
+ s.authors = ["Steve Midgley", "Elliot Nelson", "Jon Rogers"]
21
+ s.email = ["science@misuse.org", "jon@rcode5.com"]
22
+ s.homepage = "http://github.com/rcode5/mojo_magick"
23
23
  s.summary = "mojo_magick-#{MojoMagick::VERSION}"
24
- s.description = 'Simple Ruby stateless module interface to imagemagick.'
24
+ s.description = "Simple Ruby stateless module interface to imagemagick."
25
+ s.required_ruby_version = ">= 2.6.0"
25
26
 
26
- s.rubyforge_project = 'mojo_magick'
27
+ s.rubyforge_project = "mojo_magick"
27
28
 
28
29
  s.files = `git ls-files`.split("\n")
29
30
  s.test_files = `git ls-files -- {test,features}/*`.split("\n")
30
31
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
31
- s.require_paths = ['lib']
32
- s.add_development_dependency('minitest')
33
- s.add_development_dependency('rake')
34
- s.add_development_dependency('rspec-expectations')
35
- s.add_development_dependency('simplecov')
32
+ s.require_paths = ["lib"]
33
+ s.add_development_dependency("bundler")
34
+ s.add_development_dependency("bundle-audit")
35
+ s.add_development_dependency("minitest")
36
+ s.add_development_dependency("rake")
37
+ s.add_development_dependency("rspec-expectations")
38
+ s.add_development_dependency("rubocop")
39
+ s.add_development_dependency("rubocop-performance")
36
40
 
37
41
  s.post_install_message = post_install_message
38
42
  end
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require_relative "test_helper"
2
2
 
3
- IDENTIFY_FONT_RESPONSE = <<~EOF.freeze
3
+ IDENTIFY_FONT_RESPONSE = <<~EO_FONTS
4
4
  Font: Zapf-Dingbats
5
5
  family: Zapf Dingbats
6
6
  style: Normal
@@ -13,7 +13,7 @@ IDENTIFY_FONT_RESPONSE = <<~EOF.freeze
13
13
  stretch: Normal
14
14
  weight: 400
15
15
  glyphs: /Library/Fonts/Zapfino.ttf
16
- EOF
16
+ EO_FONTS
17
17
 
18
18
  class FontTest < MiniTest::Test
19
19
  def test_font
@@ -21,8 +21,8 @@ class FontTest < MiniTest::Test
21
21
  assert_nil f.name
22
22
  assert_equal f.valid?, false
23
23
 
24
- f = MojoMagick::Font.new(name: 'Zapfino', weight: 400)
25
- assert_equal f.name, 'Zapfino'
24
+ f = MojoMagick::Font.new(name: "Zapfino", weight: 400)
25
+ assert_equal f.name, "Zapfino"
26
26
  assert_equal f.valid?, true
27
27
  assert_equal f.weight, 400
28
28
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require_relative "test_helper"
2
2
 
3
3
  class FontsTest < MiniTest::Test
4
4
  def test_get_fonts
@@ -1,20 +1,20 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require_relative "test_helper"
2
2
 
3
3
  class MojoMagickTest < MiniTest::Test
4
4
  # we keep a fixtures path and a working path so that we can easily test image
5
5
  # manipulation routines without tainting the original images
6
6
  def setup
7
- @fixtures_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
8
- @working_path = File.join(@fixtures_path, 'tmp')
7
+ @fixtures_path = File.expand_path(File.join(File.dirname(__FILE__), "fixtures"))
8
+ @working_path = File.join(@fixtures_path, "tmp")
9
9
  end
10
10
 
11
11
  def reset_images
12
12
  FileUtils.rm_r(@working_path) if File.exist?(@working_path)
13
13
  FileUtils.mkdir(@working_path)
14
- Dir.glob(File.join(@fixtures_path, '*')).each do |file|
14
+ Dir.glob(File.join(@fixtures_path, "*")).each do |file|
15
15
  FileUtils.cp(file, @working_path) if File.file?(file)
16
16
  end
17
- @test_image = File.join(@working_path, '5742.jpg')
17
+ @test_image = File.join(@working_path, "5742.jpg")
18
18
  end
19
19
 
20
20
  def test_get_image_size
@@ -30,9 +30,9 @@ class MojoMagickTest < MiniTest::Test
30
30
  # test basic resizing
31
31
  reset_images
32
32
  orig_image_size = File.size(@test_image)
33
- size_test_temp = Tempfile.new('mojo_test')
33
+ size_test_temp = Tempfile.new("mojo_test")
34
34
  size_test = size_test_temp.path
35
- retval = MojoMagick.resize(@test_image, size_test, {width: 100, height: 100})
35
+ retval = MojoMagick.resize(@test_image, size_test, { width: 100, height: 100 })
36
36
  assert_equal size_test, retval
37
37
  assert_equal orig_image_size, File.size(@test_image)
38
38
  assert_equal retval, size_test
@@ -41,7 +41,7 @@ class MojoMagickTest < MiniTest::Test
41
41
  assert_equal 67, new_dimensions[:width]
42
42
 
43
43
  # we should be able to resize image right over itself
44
- retval = MojoMagick.resize(@test_image, @test_image, {width: 100, height: 100})
44
+ retval = MojoMagick.resize(@test_image, @test_image, { width: 100, height: 100 })
45
45
  assert_equal @test_image, retval
46
46
  refute_equal orig_image_size, File.size(@test_image)
47
47
  new_dimensions = MojoMagick.get_image_size(@test_image)
@@ -52,7 +52,7 @@ class MojoMagickTest < MiniTest::Test
52
52
  def test_image_resize_with_percentage
53
53
  reset_images
54
54
  original_size = MojoMagick.get_image_size(@test_image)
55
- retval = MojoMagick.resize(@test_image, @test_image, {percent: 50})
55
+ retval = MojoMagick.resize(@test_image, @test_image, { percent: 50 })
56
56
  assert_equal @test_image, retval
57
57
  new_dimensions = MojoMagick.get_image_size(@test_image)
58
58
  %i[height width].each do |dim|
@@ -63,9 +63,9 @@ class MojoMagickTest < MiniTest::Test
63
63
  def test_shrink_with_big_dimensions
64
64
  # image shouldn't resize if we specify very large dimensions and specify "shrink_only"
65
65
  reset_images
66
- size_test_temp = Tempfile.new('mojo_test')
66
+ size_test_temp = Tempfile.new("mojo_test")
67
67
  size_test = size_test_temp.path
68
- retval = MojoMagick.shrink(@test_image, size_test, {width: 1000, height: 1000})
68
+ retval = MojoMagick.shrink(@test_image, size_test, { width: 1000, height: 1000 })
69
69
  assert_equal size_test, retval
70
70
  new_dimensions = MojoMagick.get_image_size(@test_image)
71
71
  assert_equal 500, new_dimensions[:height]
@@ -75,7 +75,7 @@ class MojoMagickTest < MiniTest::Test
75
75
  def test_shrink
76
76
  reset_images
77
77
  # image should resize if we specify small dimensions and shrink_only
78
- retval = MojoMagick.shrink(@test_image, @test_image, {width: 1000, height: 100})
78
+ retval = MojoMagick.shrink(@test_image, @test_image, { width: 1000, height: 100 })
79
79
  assert_equal @test_image, retval
80
80
  new_dimensions = MojoMagick.get_image_size(@test_image)
81
81
  assert_equal 100, new_dimensions[:height]
@@ -85,7 +85,7 @@ class MojoMagickTest < MiniTest::Test
85
85
  def test_resize_with_shrink_only_options
86
86
  reset_images
87
87
  # image should resize if we specify small dimensions and shrink_only
88
- retval = MojoMagick.resize(@test_image, @test_image, {shrink_only: true, width: 400, height: 400})
88
+ retval = MojoMagick.resize(@test_image, @test_image, { shrink_only: true, width: 400, height: 400 })
89
89
  assert_equal @test_image, retval
90
90
  new_dimensions = MojoMagick.get_image_size(@test_image)
91
91
  assert_equal 400, new_dimensions[:height]
@@ -95,7 +95,8 @@ class MojoMagickTest < MiniTest::Test
95
95
  def test_expand_with_small_dim
96
96
  # image shouldn't resize if we specify small dimensions and expand_only
97
97
  reset_images
98
- retval = MojoMagick.expand(@test_image, @test_image, {width: 10, height: 10})
98
+ _orig_image_size = File.size(@test_image)
99
+ retval = MojoMagick.expand(@test_image, @test_image, { width: 10, height: 10 })
99
100
  assert_equal @test_image, retval
100
101
  new_dimensions = MojoMagick.get_image_size(@test_image)
101
102
  assert_equal 500, new_dimensions[:height]
@@ -105,7 +106,7 @@ class MojoMagickTest < MiniTest::Test
105
106
  def test_expand
106
107
  reset_images
107
108
  # image should resize if we specify large dimensions and expand_only
108
- retval = MojoMagick.expand(@test_image, @test_image, {width: 1000, height: 1000})
109
+ retval = MojoMagick.expand(@test_image, @test_image, { width: 1000, height: 1000 })
109
110
  assert_equal @test_image, retval
110
111
  new_dimensions = MojoMagick.get_image_size(@test_image)
111
112
  assert_equal 1000, new_dimensions[:height]
@@ -114,17 +115,19 @@ class MojoMagickTest < MiniTest::Test
114
115
 
115
116
  def test_invalid_images
116
117
  # test bad images
117
- bad_image = File.join(@working_path, 'not_an_image.jpg')
118
- zero_image = File.join(@working_path, 'zero_byte_image.jpg')
119
- assert_raises(MojoMagick::MojoFailed) {MojoMagick.get_image_size(bad_image)}
120
- assert_raises(MojoMagick::MojoFailed) {MojoMagick.get_image_size(zero_image)}
121
- assert_raises(MojoMagick::MojoFailed) {MojoMagick.get_image_size('/file_does_not_exist_here_ok.jpg')}
118
+ bad_image = File.join(@working_path, "not_an_image.jpg")
119
+ zero_image = File.join(@working_path, "zero_byte_image.jpg")
120
+ assert_raises(MojoMagick::MojoFailed) { MojoMagick.get_image_size(bad_image) }
121
+ assert_raises(MojoMagick::MojoFailed) { MojoMagick.get_image_size(zero_image) }
122
+ assert_raises(MojoMagick::MojoFailed) do
123
+ MojoMagick.get_image_size("/file_does_not_exist_here_ok.jpg")
124
+ end
122
125
  end
123
126
 
124
127
  def test_resize_with_fill
125
128
  reset_images
126
- @test_image = File.join(@working_path, '5742.jpg')
127
- MojoMagick.resize(@test_image, @test_image, {fill: true, width: 100, height: 100})
129
+ @test_image = File.join(@working_path, "5742.jpg")
130
+ MojoMagick.resize(@test_image, @test_image, { fill: true, width: 100, height: 100 })
128
131
  dim = MojoMagick.get_image_size(@test_image)
129
132
  assert_equal 100, dim[:width]
130
133
  assert_equal 150, dim[:height]
@@ -132,8 +135,8 @@ class MojoMagickTest < MiniTest::Test
132
135
 
133
136
  def test_resize_with_fill_and_crop
134
137
  reset_images
135
- @test_image = File.join(@working_path, '5742.jpg')
136
- MojoMagick.resize(@test_image, @test_image, {fill: true, crop: true, width: 150, height: 120})
138
+ @test_image = File.join(@working_path, "5742.jpg")
139
+ MojoMagick.resize(@test_image, @test_image, { fill: true, crop: true, width: 150, height: 120 })
137
140
  dim = MojoMagick.get_image_size(@test_image)
138
141
  assert_equal 150, dim[:width]
139
142
  assert_equal 120, dim[:height]
@@ -141,25 +144,25 @@ class MojoMagickTest < MiniTest::Test
141
144
 
142
145
  def test_tempfile
143
146
  # Create a tempfile and return the path
144
- filename = MojoMagick.tempfile('binary data')
145
- File.open(filename, 'rb') do |f|
146
- assert_equal f.read, 'binary data'
147
+ filename = MojoMagick.tempfile("binary data")
148
+ File.open(filename, "rb") do |f|
149
+ assert_equal f.read, "binary data"
147
150
  end
148
151
  end
149
152
 
150
153
  def test_label
151
154
  reset_images
152
- out_image = File.join(@working_path, 'label_test.png')
155
+ out_image = File.join(@working_path, "label_test.png")
153
156
 
154
157
  MojoMagick.convert do |c|
155
- c.label 'rock the house'
158
+ c.label "rock the house"
156
159
  c.file out_image
157
160
  end
158
161
  end
159
162
 
160
163
  def test_label_with_quote
161
164
  reset_images
162
- out_image = File.join(@working_path, 'label_test.png')
165
+ out_image = File.join(@working_path, "label_test.png")
163
166
 
164
167
  MojoMagick.convert do |c|
165
168
  c.label 'rock "the house'
@@ -169,17 +172,17 @@ class MojoMagickTest < MiniTest::Test
169
172
 
170
173
  def test_label_with_apostrophe
171
174
  reset_images
172
- out_image = File.join(@working_path, 'label_test.png')
175
+ out_image = File.join(@working_path, "label_test.png")
173
176
 
174
177
  MojoMagick.convert do |c|
175
- c.label 'rock \'the house'
178
+ c.label "rock 'the house"
176
179
  c.file out_image
177
180
  end
178
181
  end
179
182
 
180
183
  def test_label_with_quotes
181
184
  reset_images
182
- out_image = File.join(@working_path, 'label_test.png')
185
+ out_image = File.join(@working_path, "label_test.png")
183
186
 
184
187
  MojoMagick.convert do |c|
185
188
  c.label 'this is "it!"'
@@ -189,23 +192,25 @@ class MojoMagickTest < MiniTest::Test
189
192
 
190
193
  def test_bad_command
191
194
  MojoMagick.convert do |c|
192
- c.unknown_option 'fail'
193
- c.file 'boogabooga.whatever'
195
+ c.unknown_option "fail"
196
+ c.file "boogabooga.whatever"
194
197
  end
195
198
  rescue MojoMagick::MojoFailed => e
196
- assert e.message.include?('unrecognized option'), 'Unable to find ImageMagick commandline error in the message'
197
- assert e.message.include?('convert.c/ConvertImageCommand'), 'Unable to find ImageMagick commandline error in the message'
199
+ assert e.message.include?("unrecognized option"),
200
+ "Unable to find ImageMagick commandline error in the message"
201
+ assert e.message.include?("convert.c/ConvertImageCommand"),
202
+ "Unable to find ImageMagick commandline error in the message"
198
203
  end
199
204
 
200
205
  def test_blob
201
206
  reset_images
202
207
 
203
208
  # RGB8 test
204
- data = (16.times.map { [rand > 0.5 ? 0 : 255] * 3 }).flatten
205
- bdata = data.pack 'C' * data.size
206
- out = 'out.png'
209
+ data = (Array.new(16) { [rand > 0.5 ? 0 : 255] * 3 }).flatten
210
+ bdata = data.pack "C" * data.size
211
+ out = "out.png"
207
212
  MojoMagick.convert(nil, "png:#{out}") do |c|
208
- c.blob bdata, format: :rgb, depth: 8, size: '4x4'
213
+ c.blob bdata, format: :rgb, depth: 8, size: "4x4"
209
214
  end
210
215
  r = MojoMagick.get_image_size(out)
211
216
  assert r[:height] == 4
@@ -214,13 +219,13 @@ class MojoMagickTest < MiniTest::Test
214
219
 
215
220
  def test_command_helpers
216
221
  reset_images
217
- test_image = File.join(@working_path, '5742.jpg')
218
- out_image = File.join(@working_path, 'out1.jpg')
222
+ test_image = File.join(@working_path, "5742.jpg")
223
+ out_image = File.join(@working_path, "out1.jpg")
219
224
 
220
225
  # Simple convert test
221
226
  MojoMagick.convert do |c|
222
227
  c.file test_image
223
- c.crop '92x64+0+0'
228
+ c.crop "92x64+0+0"
224
229
  c.repage!
225
230
  c.file out_image
226
231
  end
@@ -230,7 +235,7 @@ class MojoMagickTest < MiniTest::Test
230
235
 
231
236
  # Simple mogrify test
232
237
  MojoMagick.mogrify do |m|
233
- m.crop '32x32+0+0'
238
+ m.crop "32x32+0+0"
234
239
  m.repage!
235
240
  m.file out_image
236
241
  end
@@ -240,7 +245,7 @@ class MojoMagickTest < MiniTest::Test
240
245
 
241
246
  # Convert test, using file shortcuts
242
247
  MojoMagick.convert(test_image, out_image) do |c|
243
- c.crop '100x100+0+0'
248
+ c.crop "100x100+0+0"
244
249
  c.repage!
245
250
  end
246
251
  retval = MojoMagick.get_image_size(out_image)
@@ -248,26 +253,26 @@ class MojoMagickTest < MiniTest::Test
248
253
  assert_equal 100, retval[:height]
249
254
 
250
255
  # Mogrify test, using file shortcut
251
- MojoMagick.mogrify(out_image) { |m| m.shave('25x25').repage! }
256
+ MojoMagick.mogrify(out_image) { |m| m.shave("25x25").repage! }
252
257
  retval = MojoMagick.get_image_size(out_image)
253
258
  assert_equal 50, retval[:width]
254
259
  assert_equal 50, retval[:height]
255
260
 
256
261
  # RGB8 test
257
- bdata = 'aaaaaabbbbbbccc'
258
- out = 'out.png'
262
+ bdata = "aaaaaabbbbbbccc"
263
+ out = "out.png"
259
264
  MojoMagick.convert do |c|
260
- c.blob bdata, format: :rgb, depth: 8, size: '5x1'
265
+ c.blob bdata, format: :rgb, depth: 8, size: "5x1"
261
266
  c.file out
262
267
  end
263
268
  r = MojoMagick.get_image_size(out)
264
269
  assert r[:height] == 1
265
270
  assert r[:width] == 5
266
271
 
267
- bdata = '1111222233334444'
268
- out = 'out.png'
272
+ bdata = "1111222233334444"
273
+ out = "out.png"
269
274
  MojoMagick.convert do |c|
270
- c.blob bdata, format: :rgba, depth: 8, size: '4x1'
275
+ c.blob bdata, format: :rgba, depth: 8, size: "4x1"
271
276
  c.file out
272
277
  end
273
278
  r = MojoMagick.get_image_size(out)