2009-10-29 05:18:24 +00:00
|
|
|
module ScreenshotHelper
|
2009-10-30 03:13:09 +00:00
|
|
|
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'
|
|
|
|
##
|
2009-10-30 03:44:01 +00:00
|
|
|
|
2009-10-30 03:13:09 +00:00
|
|
|
if (fwidth >= fheight) then
|
2009-10-30 03:44:01 +00:00
|
|
|
if (fwidth >= max) then
|
|
|
|
width = max
|
|
|
|
height = ((fheight / fwidth.to_f) * max).to_i
|
2009-10-30 03:13:09 +00:00
|
|
|
else
|
2009-10-30 03:44:01 +00:00
|
|
|
width = fwidth
|
|
|
|
height = fheight
|
2009-10-30 03:13:09 +00:00
|
|
|
end
|
2009-10-30 03:44:01 +00:00
|
|
|
elsif (fheight > fwidth) then
|
|
|
|
if (fheight > max) then
|
|
|
|
height = max
|
|
|
|
width = (( fwidth / fheight.to_f ) * max).to_i
|
2009-10-30 03:13:09 +00:00
|
|
|
else
|
2009-10-30 03:44:01 +00:00
|
|
|
height = fheight
|
|
|
|
width = fwidth
|
2009-10-30 03:13:09 +00:00
|
|
|
end
|
2009-10-30 03:44:01 +00:00
|
|
|
else
|
|
|
|
width = fwidth
|
|
|
|
height = fheight
|
2009-10-30 03:13:09 +00:00
|
|
|
end
|
2009-10-30 03:44:01 +00:00
|
|
|
|
2009-10-30 03:13:09 +00:00
|
|
|
return [width, height]
|
|
|
|
end
|
2009-10-29 05:18:24 +00:00
|
|
|
end
|