Permalink
Browse files

Merge pull request #2 from jdelStrother/thumbnail_rounding

Fix occasional thumbnail size mismatch due to float precision errors
  • Loading branch information...
2 parents 8c755b0 + cfc6c74 commit dc36ddaadc46aecdef907de3c41a9d14d28ba8d8 @adkron adkron committed May 17, 2012
Showing with 18 additions and 1 deletion.
  1. +1 −1 lib/image_science/image_science.rb
  2. +17 −0 test/test_image_science.rb
@@ -57,7 +57,7 @@ def thumbnail(size) # :yields: image
w, h = width, height
scale = size.to_f / (w > h ? w : h)
- self.resize((w * scale).to_i, (h * scale).to_i) do |image|
+ self.resize((w * scale).round, (h * scale).round) do |image|
yield image
end
end
@@ -157,4 +157,21 @@ def test_resize_negative
refute File.exists?(@tmppath)
end
+
+ def test_thumbnail
+ ImageScience.with_image @path do |img|
+ img.thumbnail(29) do |thumb|
+ assert thumb.save(@tmppath)
+ end
+ end
+
+ assert File.exists?(@tmppath)
+
+ ImageScience.with_image @tmppath do |img|
+ assert_kind_of ImageScience, img
+ assert_equal 29, img.height
+ assert_equal 29, img.width
+ end
+ end
+
end

0 comments on commit dc36dda

Please sign in to comment.