image_proc 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.0.0 / 2009-01-09
2
+
3
+ * Make all methods return the destination path only
4
+
1
5
  === 1.0.3 / 2009-01-09
2
6
 
3
7
  * Ensure the destination path is always returned
data/lib/image_proc.rb CHANGED
@@ -4,12 +4,12 @@ require 'open3'
4
4
  # design. Sort of like the Processors in attachment_fu but less. Less.
5
5
  #
6
6
  # width, height = ImageProc.get_bounds("image.png")
7
- # thumb_filename = ImageProc.resize("image.png", "thumb.png", :width => 50. :height => 50)
7
+ # destination_path = ImageProc.resize("image.png", "thumb.png", :width => 50. :height => 50)
8
8
  #
9
9
  # The whole idea is: a backend does not have to support cropping (we don't do it), it has only to be able to resize,
10
10
  # and a backend should have 2 public methods. That's the game.
11
11
  class ImageProc
12
- VERSION = '1.0.3'
12
+ VERSION = '2.0.0'
13
13
 
14
14
  class Error < RuntimeError; end
15
15
  class MissingInput < Error; end
@@ -62,8 +62,8 @@ class ImageProc
62
62
  end
63
63
  end
64
64
 
65
- def resize_with_geom_string(from_path, to_path, str) #:nodoc:
66
- w, h = opts.scan(/^\d+x\d+$/).to_a.flatten
65
+ def resize_with_geom_string(from_path, to_path, geom_str) #:nodoc:
66
+ w, h = geom_str.scan(/^(\d+)x(\d+)$/).to_a.flatten.map{|e| e.to_i }
67
67
  resize(from_path, to_path, :width => w, :height => h)
68
68
  result_w, result_h = get_bounds(to_path)
69
69
  [to_path, result_w, result_h]
@@ -87,7 +87,7 @@ class ImageProc
87
87
  if opts[:width] && opts[:height] && opts[:fill]
88
88
  resize_fit_fill(from_path, to_path, opts[:width], opts[:height])
89
89
  elsif opts[:width] && opts[:height]
90
- resize_fit(from_path, to_path, opts[:width], opts[:height])
90
+ resize_fit_both(from_path, to_path, opts[:width], opts[:height])
91
91
  elsif opts[:width]
92
92
  resize_fit_width(from_path, to_path, opts[:width])
93
93
  elsif opts[:height]
@@ -110,6 +110,7 @@ class ImageProc
110
110
  validate_input_output_files(from_path, to_path)
111
111
  @target_w, @target_h = to_width, to_height
112
112
  resetting_state_afterwards { process_exact }
113
+ to_path
113
114
  end
114
115
 
115
116
  # Resize an image fitting it into a rect.
@@ -117,6 +118,7 @@ class ImageProc
117
118
  validate_input_output_files(from_path, to_path)
118
119
  @target_w, @target_h = fit_sizes(get_bounds(from_path), :width => to_width, :height => to_height)
119
120
  resetting_state_afterwards { process_exact }
121
+ to_path
120
122
  end
121
123
  alias_method :resize_fit, :resize_fit_both
122
124
 
@@ -126,6 +128,7 @@ class ImageProc
126
128
 
127
129
  @target_w, @target_h = fit_sizes get_bounds(from_path), :width => width
128
130
  resetting_state_afterwards { process_exact }
131
+ to_path
129
132
  end
130
133
 
131
134
  # Same as resize_fit_width
@@ -133,6 +136,7 @@ class ImageProc
133
136
  validate_input_output_files(from_path, to_path)
134
137
  @target_w, @target_h = fit_sizes(get_bounds(from_path), :height => height)
135
138
  resetting_state_afterwards { process_exact }
139
+ to_path
136
140
  end
137
141
 
138
142
  # Will resize the image so that it's part always fills the rect of +width+ and +height+
@@ -142,6 +146,7 @@ class ImageProc
142
146
  validate_input_output_files(from_path, to_path)
143
147
  @target_w, @target_h = fit_sizes_with_crop get_bounds(from_path), :height => height, :width => width
144
148
  resetting_state_afterwards { process_exact }
149
+ to_path
145
150
  end
146
151
 
147
152
  # Will fit the passed array of [input_width, input_heitght] proportionally and return an array of
@@ -225,7 +230,6 @@ class ImageProc
225
230
  # cleanup any stale ivars and return the path to result and the resulting bounds
226
231
  def resetting_state_afterwards
227
232
  begin
228
- @dest = @dest % [@target_w, @target_h] if File.basename(@dest).include?('%')
229
233
  kept = [@dest, @target_w, @target_h]; yield
230
234
  ensure
231
235
  @source, @dest, @source_w, @dest_w, @source_h, @dest_h = nil
@@ -66,7 +66,7 @@ module ResizeTestHelper
66
66
 
67
67
  sources.each_with_index do | source, index |
68
68
  assert_nothing_raised do
69
- path, w, h = @processor.resize_exact(source, OUTPUTS + '/' + names[index], 65, 65)
69
+ path = @processor.resize_exact(source, OUTPUTS + '/' + names[index], 65, 65)
70
70
  assert_equal OUTPUTS + '/' + File.basename(source), path, "The proc should return the path to the result as first ret"
71
71
  end
72
72
 
@@ -79,7 +79,7 @@ module ResizeTestHelper
79
79
  def test_resize_fitting_proportionally_into_square
80
80
  with_each_horizontal_path_and_name do | source, name |
81
81
  assert_nothing_raised do
82
- path, w, h = @processor.resize_fit(source, OUTPUTS + '/' + name, 300, 300)
82
+ path = @processor.resize_fit(source, OUTPUTS + '/' + name, 300, 300)
83
83
  assert_equal OUTPUTS + '/' + File.basename(source), path, "The proc should return the path to the result as first ret"
84
84
  end
85
85
 
@@ -100,7 +100,7 @@ module ResizeTestHelper
100
100
  def test_fit_square_is_alias_for_proportional_resize
101
101
  with_each_horizontal_path_and_name do | source, name |
102
102
  assert_nothing_raised do
103
- path, w, h = @processor.resize_fit_square(source, OUTPUTS + '/' + name, 300)
103
+ path = @processor.resize_fit_square(source, OUTPUTS + '/' + name, 300)
104
104
  assert_equal OUTPUTS + '/' + File.basename(source), path, "The proc should return the path to the result as first ret"
105
105
  end
106
106
 
@@ -129,24 +129,13 @@ module ResizeTestHelper
129
129
  path, w, h = @processor.resize_fit(source, OUTPUTS + '/' + name, 100, 20)
130
130
  assert_equal OUTPUTS + '/' + File.basename(source), path, "The proc should return the path to the result as first ret"
131
131
  end
132
-
132
+
133
133
  result_p = OUTPUTS + '/' + File.basename(source)
134
134
  assert File.exist?(result_p), "#{result_p} should have been created"
135
135
  assert_equal [13, 20], get_bounds(result_p), "The image of #{get_bounds(source).join("x")} should have been fit into rect proortionally"
136
136
  end
137
137
  end
138
138
 
139
- def test_replaces_wildcards_in_filenames_after_resizing
140
- source = INPUTS + '/' + @landscapes[0]
141
- with_wildcards = OUTPUTS + '/resized_%dx%d' + File.extname(@landscapes[0])
142
- reference_path = with_wildcards % [300, 200]
143
- assert_nothing_raised do
144
- path, w, h = @processor.resize_fit(source, with_wildcards, 300, 300)
145
- assert_equal path, reference_path, "The wildcards should be replaced with computed width and height and the file saved"
146
- assert_equal [300, 200], get_bounds(reference_path)
147
- end
148
- end
149
-
150
139
  def test_resize_is_alias_for_fit_with_geometry_string
151
140
  with_each_horizontal_path_and_name do | source, name |
152
141
  assert_nothing_raised { @processor.resize(source, OUTPUTS + '/' + name, :width => 300, :height => 300) }
@@ -210,8 +199,11 @@ module ResizeTestHelper
210
199
  end
211
200
 
212
201
  result_p = OUTPUTS + '/' + File.basename(source)
213
- assert File.exist?(result_p), "#{result_p} should have been created"
214
- assert_equal [323, 485], get_bounds(result_p), "The image of #{get_bounds(source).join("x")} should have been fit into width"
202
+
203
+ assert File.exist?(result_p),
204
+ "#{result_p} should have been created"
205
+ assert_equal [323, 485], get_bounds(result_p),
206
+ "The image of #{get_bounds(source).join("x")} should have been fit into width"
215
207
  end
216
208
  end
217
209
 
@@ -3,14 +3,17 @@ require 'fileutils'
3
3
  require 'resize_test_helper'
4
4
  require 'image_proc'
5
5
 
6
- #class TestQuickProcessViaClassWithGeomString < Test::Unit::TestCase
7
- # def test_works
8
- # source = File.dirname(__FILE__) + '/input/horizontal.jpg'
9
- # dest = File.dirname(__FILE__) + '/output/resized.jpg'
10
- # assert_nothing_raised { ImageProc.resize(source, dest, "50x50") }
11
- # FileUtils.rm dest
12
- # end
13
- #end
6
+ # This will go away.
7
+ class TestQuickProcessViaClassWithGeomString < Test::Unit::TestCase
8
+ def test_works
9
+ source = File.dirname(__FILE__) + '/input/horizontal.jpg'
10
+ dest = File.dirname(__FILE__) + '/output/resized.jpg'
11
+ ImageProc.resize_with_geom_string(source, dest, "50x50")
12
+ assert_equal [50,33], ImageProc.get_bounds(dest)
13
+ ensure
14
+ FileUtils.rm(dest) if File.exist?(dest)
15
+ end
16
+ end
14
17
 
15
18
  class TestQuickProcessWithOptions < Test::Unit::TestCase
16
19
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: image_proc
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 2.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Julik
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-03 00:00:00 Z
13
+ date: 2011-07-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe