mojo_magick 0.5.6 → 0.5.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 50a45302825af74fc985fd903d6f493407c243f4
4
- data.tar.gz: 7d535139b1d46cf04ffa4b003d290b3c806e7e2a
2
+ SHA256:
3
+ metadata.gz: 30925f12cdcc0bbe8f6626d1f68266f00be28abe536a4c925522d8cbb99750dc
4
+ data.tar.gz: 1bf5dbdb09fa28ec7e5c0167d32c153f740d00c7541685840ce720d83f53c0fe
5
5
  SHA512:
6
- metadata.gz: fd3cfe567c2f35d7a87a68843b7139f728ad388fdecbbac03ef0a1f97468dfe3c0b71fb4705372e5b36044c9a0f0cc2346efe8fa86119cf6493bcb462dfaedc3
7
- data.tar.gz: 9b8db5160797881095e8551a4540cd4e10ef8f23efb4d8d2d22bcef9d2cc45f703c263442822caf04f169ff64192a511259eb1bbd44b2c5bdcbf523b79fa509c
6
+ metadata.gz: 29735844a173bc70ded217d142c8c11af8b78880f1396d4678837182d27c57f18e79b17c673d0174ab328e08f47a33aecb522e704701539c44f8723493bc8bab
7
+ data.tar.gz: 93907724a1c2822532e6009aef4a65b59db0e0197abbe214196b202dfbad337ab95ced02d38576ab68c420692403da1963e8d940637c99b627053afb9be7eb99
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.6.6
@@ -1,26 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mojo_magick (0.5.6)
4
+ mojo_magick (0.5.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.2.4)
10
- multi_json (1.8.2)
11
- rake (0.9.2.2)
12
- rspec-expectations (2.14.3)
13
- diff-lcs (>= 1.1.3, < 2.0)
14
- simplecov (0.7.1)
15
- multi_json (~> 1.0)
16
- simplecov-html (~> 0.7.1)
17
- simplecov-html (0.7.1)
9
+ diff-lcs (1.3)
10
+ docile (1.3.2)
11
+ json (2.2.0)
12
+ minitest (5.14.2)
13
+ rake (12.3.3)
14
+ rspec-expectations (3.9.0)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.9.0)
17
+ rspec-support (3.9.0)
18
+ simplecov (0.17.0)
19
+ docile (~> 1.1)
20
+ json (>= 1.8, < 3)
21
+ simplecov-html (~> 0.10.0)
22
+ simplecov-html (0.10.2)
18
23
 
19
24
  PLATFORMS
20
25
  ruby
21
26
 
22
27
  DEPENDENCIES
28
+ minitest
23
29
  mojo_magick!
24
30
  rake
25
31
  rspec-expectations
26
32
  simplecov
33
+
34
+ BUNDLED WITH
35
+ 1.17.2
data/README.md CHANGED
@@ -10,6 +10,7 @@ This tool came about because I wanted a fast, simple, lightweight, nothing-goes-
10
10
  because-it's-too-simple-to-break image tool.
11
11
 
12
12
  [![Gem Version](https://badge.fury.io/rb/mojo_magick.png)](http://badge.fury.io/rb/mojo_magick)
13
+ [![Build Status](https://circleci.com/gh/rcode5/mojo_magick/tree/master.svg?style=shield&circle-token=8d2252bd460bf1a7cdaad5c2e169698605afb981)]()
13
14
 
14
15
  Using it
15
16
  ========
data/Rakefile CHANGED
@@ -1,20 +1,13 @@
1
1
  require 'rubygems'
2
+ require 'rake/testtask'
2
3
 
3
- task 'default' => :test
4
-
5
- desc "Default: run tests"
6
- task :test do
7
- require 'simplecov'
8
- SimpleCov.start
9
- require 'rake/runtest'
10
- files = Dir.glob(File.join(File.dirname(__FILE__), 'test/*_test.rb'))
11
- files.each do |f|
12
- Rake.run_tests f
13
- end
4
+ task default: 'test'
5
+ Rake::TestTask.new do |task|
6
+ task.pattern = 'test/*_test.rb'
14
7
  end
15
8
 
16
- desc "Build gem"
9
+ desc 'Build gem'
17
10
  task :build do
18
11
  `rm mojo_magick-*.gem`
19
- puts `gem build mojo_magick.gemspec`
12
+ puts `gem build mojo_magick.gemspec`
20
13
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'mojo_magick'
5
5
 
6
- MojoMagick::convert(nil, 'animated.gif') do |c|
6
+ MojoMagick.convert(nil, 'animated.gif') do |c|
7
7
  c.size '200x200'
8
8
  c.delay 100
9
9
  c.image_block do # first layer
@@ -19,4 +19,3 @@ MojoMagick::convert(nil, 'animated.gif') do |c|
19
19
  c.label 'SE'
20
20
  end
21
21
  end
22
-
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'mojo_magick'
5
5
 
6
- MojoMagick::convert(nil, 'composite_out.png') do |c|
6
+ MojoMagick.convert(nil, 'composite_out.png') do |c|
7
7
  c.size '200x200'
8
8
  c.delay 100
9
9
  c.image_block do # first layer
@@ -20,4 +20,3 @@ MojoMagick::convert(nil, 'composite_out.png') do |c|
20
20
  end
21
21
  c.composite
22
22
  end
23
-
data/init.rb CHANGED
@@ -1,3 +1 @@
1
- require File::expand_path(File::join(File::dirname(__FILE__), 'lib', 'mojo_magick'))
2
-
3
-
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'mojo_magick'))
@@ -3,10 +3,10 @@ module ImageMagick
3
3
  def get_fonts
4
4
  @parser ||= MojoMagick::Util::Parser.new
5
5
  raw_fonts = begin
6
- self.raw_command('identify', '-list font')
7
- rescue Exception => ex
8
- puts ex
9
- puts "Failed to execute font list with raw_command - trying straight up execute"
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
10
  `convert -list font`
11
11
  end
12
12
  @parser.parse_fonts(raw_fonts)
@@ -20,71 +20,66 @@ module ImageMagick
20
20
  # MiniMagick::Image::set_limit(:disk => 5)
21
21
  # # set memory to 32mb, map to 64mb and disk to 0
22
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
23
+ def set_limits(options)
24
+ options.each do |resource, value|
25
+ @@resource_limits[resource.to_s.downcase.to_sym] = value.to_s
28
26
  end
27
+ end
29
28
 
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
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
37
34
  end
35
+ end
38
36
 
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
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
49
45
  end
46
+ end
50
47
 
51
- # returns the default limits that imagemagick is using, when run with no "-limit" parameters
48
+ # returns the default limits that imagemagick is using, when run with no "-limit" parameters
52
49
  # options:
53
50
  # :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
51
+ def get_default_limits(options = {})
52
+ parse_limits(options.merge(get_current_limits: false))
53
+ end
58
54
 
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
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
64
59
 
65
- alias :get_limits :get_current_limits
60
+ alias get_limits get_current_limits
66
61
 
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
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
80
75
 
81
- # returns a string suitable for passing as a set of imagemagick params
76
+ # returns a string suitable for passing as a set of imagemagick params
82
77
  # that contains all the limit constraints
83
78
  def get_limits_as_params
84
79
  retval = ''
85
80
  # we upcase the value here for newer versions of ImageMagick (>=6.8.x)
86
81
  @@resource_limits.each do |type, value|
87
- retval += " -limit #{type.to_s} #{value.upcase} "
82
+ retval += " -limit #{type} #{value.upcase} "
88
83
  end
89
84
  retval
90
85
  end
@@ -1,7 +1,11 @@
1
1
  class Hash
2
2
  def symbolize_keys!
3
3
  keys.each do |key|
4
- self[(key.to_sym rescue key) || key] = delete(key)
4
+ self[begin
5
+ key.to_sym
6
+ rescue StandardError
7
+ key
8
+ end || key] = delete(key)
5
9
  end
6
10
  self
7
11
  end
@@ -1,17 +1,16 @@
1
- cwd = File::dirname(__FILE__)
1
+ cwd = File.dirname(__FILE__)
2
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')
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
12
  require 'tempfile'
13
13
 
14
-
15
14
  # MojoMagick is a stateless set of module methods which present a convient interface
16
15
  # for accessing common tasks for ImageMagick command line library.
17
16
  #
@@ -62,53 +61,50 @@ require 'tempfile'
62
61
  # instead of '-' versions.
63
62
  #
64
63
  module MojoMagick
65
-
66
64
  # enable resource limiting functionality
67
65
  extend ImageMagick::ResourceLimits
68
66
  extend ImageMagick::Fonts
69
67
 
70
- def MojoMagick::windows?
71
- mem_fix = 1
68
+ def self.windows?
72
69
  !(RUBY_PLATFORM =~ /win32/).nil?
73
70
  end
74
71
 
75
- def MojoMagick::execute(command, args, options = {})
72
+ def self.execute(command, args, _options = {})
76
73
  # this suppress error messages to the console
77
74
  # err_pipe = windows? ? "2>nul" : "2>/dev/null"
78
- begin
79
- execute = "#{command} #{get_limits_as_params} #{args}"
80
- out, outerr, status = Open3.capture3(execute)
81
- CommandStatus.new execute, out, outerr, status
82
- rescue Exception => e
83
- raise MojoError, "#{e.class}: #{e.message}"
84
- end
75
+
76
+ execute = "#{command} #{get_limits_as_params} #{args}"
77
+ out, outerr, status = Open3.capture3(execute)
78
+ CommandStatus.new execute, out, outerr, status
79
+ rescue Exception => e
80
+ raise MojoError, "#{e.class}: #{e.message}"
85
81
  end
86
-
87
- def MojoMagick::execute!(command, args, options = {})
82
+
83
+ def self.execute!(command, args, options = {})
88
84
  # this suppress error messages to the console
89
85
  # err_pipe = windows? ? "2>nul" : "2>/dev/null"
90
86
  status = execute(command, args, options)
91
- if !status.success?
87
+ unless status.success?
92
88
  err_msg = options[:err_msg] || "MojoMagick command failed: #{command}."
93
89
  raise(MojoFailed, "#{err_msg} (Exit status: #{status.exit_code})\n Command: #{status.command}\n Error: #{status.error}")
94
90
  end
95
91
  status.return_value
96
92
  end
97
-
98
- def MojoMagick::raw_command(*args)
99
- self.execute! *args
93
+
94
+ def self.raw_command(*args)
95
+ execute!(*args)
100
96
  end
101
97
 
102
- def MojoMagick::shrink(source_file, dest_file, options)
98
+ def self.shrink(source_file, dest_file, options)
103
99
  opts = options.dup
104
100
  opts.delete(:expand_only)
105
- MojoMagick::resize(source_file, dest_file, opts.merge(:shrink_only => true))
101
+ MojoMagick.resize(source_file, dest_file, opts.merge(shrink_only: true))
106
102
  end
107
103
 
108
- def MojoMagick::expand(source_file, dest_file, options)
104
+ def self.expand(source_file, dest_file, options)
109
105
  opts = options.dup
110
106
  opts.delete(:shrink_only)
111
- MojoMagick::resize(source_file, dest_file, opts.merge(:expand_only => true))
107
+ MojoMagick.resize(source_file, dest_file, opts.merge(expand_only: true))
112
108
  end
113
109
 
114
110
  # resizes an image and returns the filename written to
@@ -116,13 +112,12 @@ module MojoMagick
116
112
  # :width / :height => scale to these dimensions
117
113
  # :scale => pass scale options such as ">" to force shrink scaling only or "!" to force absolute width/height scaling (do not preserve aspect ratio)
118
114
  # :percent => scale image to this percentage (do not specify :width/:height in this case)
119
- def MojoMagick::resize(source_file, dest_file, options)
120
- retval = nil
115
+ def self.resize(source_file, dest_file, options)
121
116
  scale_options = []
122
- scale_options << ">" unless options[:shrink_only].nil?
123
- scale_options << "<" unless options[:expand_only].nil?
124
- scale_options << "!" unless options[:absolute_aspect].nil?
125
- scale_options << "^" unless options[:fill].nil?
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?
126
121
  scale_options = scale_options.join
127
122
 
128
123
  extras = []
@@ -134,37 +129,39 @@ module MojoMagick
134
129
  raise MojoMagickError, "Unknown options for method resize: #{options.inspect}"
135
130
  end
136
131
  if !options[:fill].nil? && !options[:crop].nil?
137
- extras << "-gravity Center"
132
+ extras << '-gravity Center'
138
133
  extras << "-extent #{geometry}"
139
134
  end
140
- retval = raw_command("convert", "\"#{source_file}\" -resize \"#{geometry}#{scale_options}\" #{extras.join(' ')} \"#{dest_file}\"")
135
+ raw_command('convert', "\"#{source_file}\" -resize \"#{geometry}#{scale_options}\" #{extras.join(' ')} \"#{dest_file}\"")
141
136
  dest_file
142
137
  end
143
138
 
144
- def MojoMagick::available_fonts
139
+ def self.available_fonts
145
140
  # returns width, height of image if available, nil if not
146
141
  Font.all
147
142
  end
148
143
 
149
- def MojoMagick::get_format(source_file, format_string)
150
- retval = raw_command("identify", "-format \"#{format_string}\" \"#{source_file}\"")
144
+ def self.get_format(source_file, format_string)
145
+ raw_command('identify', "-format \"#{format_string}\" \"#{source_file}\"")
151
146
  end
152
-
147
+
153
148
  # returns an empty hash or a hash with :width and :height set (e.g. {:width => INT, :height => INT})
154
149
  # raises MojoFailed when results are indeterminate (width and height could not be determined)
155
- def MojoMagick::get_image_size(source_file)
150
+ def self.get_image_size(source_file)
156
151
  # returns width, height of image if available, nil if not
157
- retval = self.get_format(source_file, %q|w:%w h:%h|)
158
- return {} if !retval
159
- width = retval.match(%r{w:([0-9]+) })
152
+ retval = get_format(source_file, 'w:%w h:%h')
153
+ return {} unless retval
154
+
155
+ width = retval.match(/w:([0-9]+) /)
160
156
  width = width ? width[1].to_i : nil
161
- height = retval.match(%r{h:([0-9]+)})
157
+ height = retval.match(/h:([0-9]+)/)
162
158
  height = height ? height[1].to_i : nil
163
159
  raise(MojoFailed, "Indeterminate results in get_image_size: #{source_file}") if !height || !width
164
- {:width=>width, :height=>height}
160
+
161
+ { width: width, height: height }
165
162
  end
166
163
 
167
- def MojoMagick::convert(source = nil, dest = nil)
164
+ def self.convert(source = nil, dest = nil)
168
165
  opts = OptBuilder.new
169
166
  opts.file source if source
170
167
  yield opts
@@ -172,27 +169,22 @@ module MojoMagick
172
169
  raw_command('convert', opts.to_s)
173
170
  end
174
171
 
175
- def MojoMagick::mogrify(dest = nil)
172
+ def self.mogrify(dest = nil)
176
173
  opts = OptBuilder.new
177
174
  yield opts
178
175
  opts.file dest if dest
179
176
  raw_command('mogrify', opts.to_s)
180
177
  end
181
178
 
182
- def MojoMagick::tempfile(*opts)
183
- begin
184
- data = opts[0]
185
- rest = opts[1]
186
- ext = rest && rest[:format]
187
- file = Tempfile.new(["mojo", ext ? '.' + ext.to_s : ''])
188
- file.binmode
189
- file.write(data)
190
- file.path
191
- rescue Exception => ex
192
- raise
193
- ensure
194
- file.close
195
- end
179
+ def self.tempfile(*opts)
180
+ data = opts[0]
181
+ rest = opts[1]
182
+ ext = rest && rest[:format]
183
+ file = Tempfile.new(['mojo', ext ? '.' + ext.to_s : ''])
184
+ file.binmode
185
+ file.write(data)
186
+ file.path
187
+ ensure
188
+ file.close
196
189
  end
197
-
198
190
  end # MojoMagick