Skip to content

Commit

Permalink
Merge branch 'i0rek-loop' into development
Browse files Browse the repository at this point in the history
* i0rek-loop:
  Make spec text more descriptive.
  wip
  • Loading branch information
berkes committed Feb 27, 2015
2 parents 418e8ff + 390a072 commit a77cffc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/smartcropper.rb
Expand Up @@ -110,6 +110,7 @@ def smart_crop_by_trim(requested_x, requested_y)
bottom -= slice_height
end

break if slice_height == step_size
height = (bottom - top)
end
end
Expand Down
Binary file added test/fixtures/small1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/small2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions test/helper.rb
Expand Up @@ -13,5 +13,12 @@

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

class Test::Unit::TestCase
def fixture_path
Pathname.new(File.join(File.expand_path(File.dirname(__FILE__)), "fixtures"))
end
end

require 'smartcropper'

19 changes: 19 additions & 0 deletions test/test_croptoelie.rb
Expand Up @@ -14,6 +14,7 @@ def setup
img = SmartCropper.new(@image)
assert_equal(img.class, SmartCropper)
end

should "create a smartcropper from an imagefile" do
img = SmartCropper.from_file(@filename)
assert_equal(img.class, SmartCropper)
Expand Down Expand Up @@ -64,6 +65,24 @@ def setup
assert_equal(img.image, @image)
end

###########################################################################
# Stuck in a loop when image is too small to slice #
###########################################################################
should "handle 1px wide images" do
@filename = fixture_path.join("small1.png")
@image = Magick::ImageList.new(@filename).last
img = SmartCropper.new(@image).smart_crop_and_scale(1, 50)
size = [img.rows, img.columns]
assert_equal([50, 1], size)
end

should "handle 5px wide images" do
@filename = fixture_path.join("small2.png")
@image = Magick::ImageList.new(@filename).last
img = SmartCropper.new(@image).smart_crop_and_scale(1, 50)
size = [img.rows, img.columns]
assert_equal([50, 1], size)
end

###########################################################################
# Images reported to fail by issue #5 #
Expand Down

0 comments on commit a77cffc

Please sign in to comment.