Skip to content

Commit

Permalink
Fix my retarted math skillz
Browse files Browse the repository at this point in the history
  • Loading branch information
zaius committed Aug 5, 2009
1 parent 359a60f commit d17a001
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions models/image.rb
Expand Up @@ -25,10 +25,13 @@ def set_default_size_and_position
# something reasonable to start off with.
# No need to call resize - it will get called because the width and
# height have changed.
if self.width > max_width and self.height > max_height
ratio = Math.min(self.width / max_width, self.height / max_height)
self.width *= ratio
self.height *= ratio
if self.width > max_width or self.height > max_height
# Calculate the ratio to multiply both width and height by that will end
# up with an image smaller than the maximum dimensions. Note that this
# must have floating point conversions, as ratio is always > 0 and < 1
ratio = Math.min(max_width.to_f / self.width, max_height.to_f / self.height)
self.width = (self.width * ratio).to_i
self.height = (self.height * ratio).to_i
end
end

Expand Down

0 comments on commit d17a001

Please sign in to comment.