Skip to content

Commit

Permalink
Adding tests for scaled resize
Browse files Browse the repository at this point in the history
  • Loading branch information
kitwalker12 committed Mar 4, 2014
1 parent fd0b8b4 commit ec222bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
imanip (0.1.4)
imanip (0.1.5)
safe_shell (~> 1.0)

GEM
Expand All @@ -10,7 +10,7 @@ GEM
mocha (0.9.8)
rake
rake (0.8.7)
safe_shell (1.0.0)
safe_shell (1.0.2)

PLATFORMS
ruby
Expand Down
16 changes: 8 additions & 8 deletions lib/imanip/imanip_magick.rb
Expand Up @@ -89,21 +89,21 @@ def crop_resize(to_file, options = {})
convert(to_file,crop_resize_string)
end
alias :crop_resized :crop_resize

def scale_resize(to_file, options = {})
@options = options.dup
parse_size_options!
crop_resize_string = ""
crop_width = @geometry[:width]
crop_height = @geometry[:height]
scale_resize_string = ""
preserve_width = @geometry[:width]
preserve_height = @geometry[:height]
scale_width = @scale[:width]
scale_height = @scale[:height]
gravity = @options.delete(:gravity) || 'center'
background = @options.delete(:background) || 'white'
crop_resize_string << " -background #{background} -scale #{to_geometry_string(:height => scale_height, :width => scale_width)} -extent #{to_geometry_string(:height => crop_height, :width => crop_width)}"
crop_resize_string << " -gravity #{gravity}"
crop_resize_string << " #{options_to_string(@options)}"
convert(to_file,crop_resize_string)
scale_resize_string << " -background #{background} -scale #{to_geometry_string(:height => preserve_height, :width => preserve_width)} -extent #{to_geometry_string(:height => scale_height, :width => scale_width)}"
scale_resize_string << " -gravity #{gravity}"
scale_resize_string << " #{options_to_string(@options)}"
convert(to_file,scale_resize_string)
end

def identify(options = {})
Expand Down
14 changes: 14 additions & 0 deletions test/test_imanip_magick.rb
Expand Up @@ -94,6 +94,20 @@ def test_crop_resize_should_crop_and_resize_image_to_exact_dimensions
assert_equal dimensions, @new_image.dimensions
end

def test_scale_resize_should_scale_and_resize_image_to_scaled_dimensions
dimensions = [400,315]
scaled = [600,315]
assert @landscape_image.scale_resize(new_image_path, :dimensions => dimensions, :scale => scaled)
@new_image = new_imanip_image(new_image_path)
assert_equal scaled, @new_image.dimensions

dimensions = [411,519]
scaled = [411,600]
assert @portrait_image.scale_resize(new_image_path, :dimensions => dimensions, :scale => scaled)
@new_image = new_imanip_image(new_image_path)
assert_equal scaled, @new_image.dimensions
end

def test_crop_resize_should_crop_and_resize_image_to_exact_dimensions_with_square_dimensions
dimensions = [100,100]
assert @landscape_image.crop_resize(new_image_path, :dimensions => dimensions)
Expand Down

0 comments on commit ec222bf

Please sign in to comment.