photogriffy.net/app/helpers/screenshot_helper.rb

36 lines
827 B
Ruby

module ScreenshotHelper
def size_calc (fwidth, fheight, max = 500)
##
## Image size calculator function.
## Inputs:
## fwidth = original file width
## fheight = original file height
## max = maximum desired dimension, default = 500px
## Outputs:
## Size array of 'width' and 'height'
##
if (fwidth >= fheight) then
if (fwidth >= max) then
width = max
height = ((fheight / fwidth.to_f) * max).to_i
else
width = fwidth
height = fheight
end
elsif (fheight > fwidth) then
if (fheight > max) then
height = max
width = (( fwidth / fheight.to_f ) * max).to_i
else
height = fheight
width = fwidth
end
else
width = fwidth
height = fheight
end
return [width, height]
end
end