mini_magick 2.0.0 → 2.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1
data/lib/mini_magick.rb CHANGED
@@ -141,21 +141,15 @@ module MiniMagick
141
141
  # If an unknown method is called then it is sent through the morgrify program
142
142
  # Look here to find all the commands (http://www.imagemagick.org/script/mogrify.php)
143
143
  def method_missing(symbol, *args)
144
- guessed_command_name = symbol.to_s.gsub('_','-')
145
-
146
- if MOGRIFY_COMMANDS.include?(guessed_command_name)
147
- args.push(@path) # push the path onto the end
148
- run_command("mogrify", "-#{guessed_command_name}", *args)
149
- self
150
- else
151
- super(symbol, *args)
144
+ combine_options do |c|
145
+ c.method_missing(symbol, *args)
152
146
  end
153
147
  end
154
148
 
155
149
  # You can use multiple commands together using this method
156
150
  def combine_options(&block)
157
151
  c = CommandBuilder.new('mogrify')
158
- block.call c
152
+ block.call(c)
159
153
  c << @path
160
154
  run(c)
161
155
  end
@@ -185,7 +179,7 @@ module MiniMagick
185
179
 
186
180
  # Outputs a carriage-return delimited format string for Unix and Windows
187
181
  def format_option(format)
188
- windows? ? "#{format}\\n" : "#{format}\\\\n"
182
+ windows? ? "\"#{format}\\n\"" : "\"#{format}\\\\n\""
189
183
  end
190
184
 
191
185
  def run_command(command, *args)
@@ -207,7 +201,7 @@ module MiniMagick
207
201
  else
208
202
  # TODO: should we do something different if the command times out ...?
209
203
  # its definitely better for logging.. otherwise we dont really know
210
- raise Error, "Command (#{command.inspect}) failed: #{{:status_code => sub.exitstatus, :output => sub.output}.inspect}"
204
+ raise Error, "Command (#{command.inspect.gsub("\\", "")}) failed: #{{:status_code => sub.exitstatus, :output => sub.output}.inspect}"
211
205
  end
212
206
  else
213
207
  sub.output
@@ -239,33 +233,33 @@ module MiniMagick
239
233
  def initialize(command, *options)
240
234
  @command = command
241
235
  @args = []
242
-
243
- options.each { |val| push(val) }
236
+ options.each { |arg| push(arg) }
244
237
  end
245
238
 
246
239
  def command
247
240
  "#{MiniMagick.processor} #{@command} #{@args.join(' ')}".strip
248
241
  end
249
242
 
250
- def method_missing(symbol, *args)
243
+ def method_missing(symbol, *options)
251
244
  guessed_command_name = symbol.to_s.gsub('_','-')
252
- if MOGRIFY_COMMANDS.include?(guessed_command_name)
253
- # This makes sure we always quote if we are passed a single
254
- # arguement with spaces in it
255
- if (args.size == 1) && (args.first.to_s.include?(' '))
256
- push("-#{guessed_command_name}")
257
- push(args.join(" "))
258
- else
259
- push("-#{guessed_command_name} #{args.join(" ")}")
260
- end
245
+ if guessed_command_name == "format"
246
+ raise Error, "You must call 'format' on the image object directly!"
247
+ elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
248
+ add(guessed_command_name, *options)
261
249
  else
262
250
  super(symbol, *args)
263
251
  end
264
252
  end
265
253
 
266
- def push(value)
267
- # args can contain characters like '>' so we must escape them, but don't quote switches
268
- @args << ((value !~ /^[\+\-]/) ? "\"#{value}\"" : value.to_s.strip)
254
+ def add(command, *options)
255
+ push "-#{command}"
256
+ if options.any?
257
+ push "\"#{options.join(" ")}\""
258
+ end
259
+ end
260
+
261
+ def push(arg)
262
+ @args << arg.strip
269
263
  end
270
264
  alias :<< :push
271
265
 
@@ -8,7 +8,7 @@ class CommandBuilderTest < Test::Unit::TestCase
8
8
  def test_basic
9
9
  c = CommandBuilder.new("test")
10
10
  c.resize "30x40"
11
- assert_equal "-resize 30x40", c.args.join(" ")
11
+ assert_equal "-resize \"30x40\"", c.args.join(" ")
12
12
  end
13
13
 
14
14
  def test_complicated
@@ -16,7 +16,7 @@ class CommandBuilderTest < Test::Unit::TestCase
16
16
  c.resize "30x40"
17
17
  c.alpha 1, 3, 4
18
18
  c.resize "mome fingo"
19
- assert_equal "-resize 30x40 -alpha 1 3 4 -resize \"mome fingo\"", c.args.join(" ")
19
+ assert_equal "-resize \"30x40\" -alpha \"1 3 4\" -resize \"mome fingo\"", c.args.join(" ")
20
20
  end
21
21
 
22
22
  def test_valid_command
@@ -28,14 +28,6 @@ class CommandBuilderTest < Test::Unit::TestCase
28
28
  assert true
29
29
  end
30
30
  end
31
-
32
- def test_full_command
33
- c = CommandBuilder.new("test")
34
- c.resize "30x40"
35
- c.alpha 1, 3, 4
36
- c.resize "mome fingo"
37
- assert_equal "test -resize 30x40 -alpha 1 3 4 -resize \"mome fingo\"", c.command
38
- end
39
31
 
40
32
  def test_dashed
41
33
  c = CommandBuilder.new("test")
data/test/image_test.rb CHANGED
@@ -77,19 +77,6 @@ class ImageTest < Test::Unit::TestCase
77
77
  image.destroy!
78
78
  end
79
79
 
80
- # def test_animation_pages
81
- # image = Image.from_file(ANIMATION_PATH)
82
- # image.format "png", 0
83
- # assert_equal "png", image[:format].downcase
84
- # image.destroy!
85
- # end
86
-
87
- # def test_animation_size
88
- # image = Image.from_file(ANIMATION_PATH)
89
- # assert_equal image[:size], 76631
90
- # image.destroy!
91
- # end
92
-
93
80
  def test_gif_with_jpg_format
94
81
  image = Image.new(GIF_WITH_JPG_EXT)
95
82
  assert_equal "gif", image[:format].downcase
@@ -120,7 +107,7 @@ class ImageTest < Test::Unit::TestCase
120
107
  image = Image.from_file(SIMPLE_IMAGE_PATH)
121
108
  image.combine_options do |c|
122
109
  c.resize "20x30!"
123
- c.blur 50
110
+ c.blur "50"
124
111
  end
125
112
 
126
113
  assert_equal 20, image[:width]
@@ -131,9 +118,12 @@ class ImageTest < Test::Unit::TestCase
131
118
 
132
119
  def test_image_combine_options_with_filename_with_minusses_in_it
133
120
  image = Image.from_file(SIMPLE_IMAGE_PATH)
121
+ background = "#000000"
134
122
  assert_nothing_raised do
135
123
  image.combine_options do |c|
136
124
  c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
125
+ c.thumbnail "300x500>"
126
+ c.background background
137
127
  end
138
128
  end
139
129
  image.destroy!
@@ -195,11 +185,25 @@ class ImageTest < Test::Unit::TestCase
195
185
  end
196
186
  assert `diff -s #{result.path} test/composited.jpg`.include?("identical")
197
187
  end
198
-
199
- # def test_mini_magick_error_when_referencing_not_existing_page
200
- # image = Image.from_file(ANIMATION_PATH)
201
- # image.format('png')
202
- # assert_equal image[:format], 'PNG'
203
- # image.destroy!
204
- # end
188
+
189
+ def test_issue_8
190
+ image = Image.from_file(SIMPLE_IMAGE_PATH)
191
+ assert_nothing_raised do
192
+ image.combine_options do |c|
193
+ c.sample "50%"
194
+ c.rotate "-90>"
195
+ end
196
+ end
197
+ image.destroy!
198
+ end
199
+
200
+ def test_throw_format_error
201
+ image = Image.from_file(SIMPLE_IMAGE_PATH)
202
+ assert_raise MiniMagick::Error do
203
+ image.combine_options do |c|
204
+ c.format "png"
205
+ end
206
+ end
207
+ image.destroy!
208
+ end
205
209
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 1
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 0
8
- - 0
9
- version: 2.0.0
8
+ - 1
9
+ version: "2.1"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Corey Johnson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-17 00:00:00 +01:00
19
+ date: 2010-08-28 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -27,6 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
+ hash: 23
30
31
  segments:
31
32
  - 0
32
33
  - 0
@@ -76,6 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  requirements:
77
78
  - - ">="
78
79
  - !ruby/object:Gem::Version
80
+ hash: 3
79
81
  segments:
80
82
  - 0
81
83
  version: "0"
@@ -84,6 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  requirements:
85
87
  - - ">="
86
88
  - !ruby/object:Gem::Version
89
+ hash: 3
87
90
  segments:
88
91
  - 0
89
92
  version: "0"