moving the screenshot sizing into a helper function.
This commit is contained in:
parent
0da2967543
commit
b86727d359
2 changed files with 30 additions and 20 deletions
|
@ -1,2 +1,29 @@
|
|||
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
|
||||
|
|
|
@ -1,24 +1,7 @@
|
|||
<%
|
||||
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
|
||||
|
||||
%>
|
||||
<% size = size_calc(@fsize[0], @fsize[1], 500) %>
|
||||
|
||||
<div class="box">
|
||||
<div class="border" style="width:<%= width %>;">
|
||||
<%= image_tag @fpath , :width => width , :height => height%>
|
||||
<div class="border" style="width:<%= size[width] %>;">
|
||||
<%= image_tag @fpath , :width => size[width] , :height => size[height] %>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue