moving the screenshot sizing into a helper function.

This commit is contained in:
Andrew Davidson 2009-10-29 20:13:09 -07:00
parent 0da2967543
commit b86727d359
2 changed files with 30 additions and 20 deletions

View file

@ -1,2 +1,29 @@
module ScreenshotHelper 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'
##
size = nil
if (fwidth >= fheight) then
if (fwidth[0] >= max) then
size[width] = max
else
size[width] = fwidth
end
else
if (fheight >= max) then
size[height] = max
size[width] = (( fwidth / fheight.to_f ) * max).to_i
else
size[height] = fheight
end
end
return [width, height]
end
end end

View file

@ -1,24 +1,7 @@
<% <% size = size_calc(@fsize[0], @fsize[1], 500) %>
width = nil ; height = nil ;
if (@fsize[0] >= @fsize[1]) then
if (@fsize[0] >= 500) then
width = 500
else
width = @fsize[0]
end
else
if (@fsize[1] >= 500) then
height = 500
width = (( @fsize[0] / @fsize[1].to_f ) * 500).to_i
else
height = @fsize[1]
end
end
%>
<div class="box"> <div class="box">
<div class="border" style="width:<%= width %>;"> <div class="border" style="width:<%= size[width] %>;">
<%= image_tag @fpath , :width => width , :height => height%> <%= image_tag @fpath , :width => size[width] , :height => size[height] %>
</div> </div>
</div> </div>