Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Refactor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
joegatt committed Sep 2, 2013
1 parent 2f3b7c4 commit f8f42ad
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions app/helpers/resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,27 @@ def crop_offsets_by_gravity(gravity, original_dimensions, cropped_dimensions)
original_width, original_height = original_dimensions
cropped_width, cropped_height = cropped_dimensions

vertical_offset = case gravity
when :north_west, :north, :north_east then 0
when :center, :east, :west then [ ((original_height - cropped_height) / 2.0).to_i, 0 ].max
when :south_west, :south, :south_east then (original_height - cropped_height).to_i
end

horizontal_offset = case gravity
when :north_west, :west, :south_west then 0
when :center, :north, :south then [ ((original_width - cropped_width) / 2.0).to_i, 0 ].max
when :north_east, :east, :south_east then (original_width - cropped_width).to_i

return [
_horizontal_offset(gravity, original_width, cropped_width),
_vertical_offset(gravity, original_height, cropped_height)
]
end

def _horizontal_offset(gravity, original_width, cropped_width)
case gravity
when :north_west, :west, :south_west then 0
when :center, :north, :south then [((original_width - cropped_width) / 2.0).to_i, 0].max
when :north_east, :east, :south_east then (original_width - cropped_width).to_i
end
end

return [ horizontal_offset, vertical_offset ]
def _vertical_offset(gravity, original_height, cropped_height)
case gravity
when :north_west, :north, :north_east then 0
when :center, :east, :west then [((original_height - cropped_height) / 2.0).to_i, 0].max
when :south_west, :south, :south_east then (original_height - cropped_height).to_i
end
end
end

0 comments on commit f8f42ad

Please sign in to comment.