diff --git a/app/helpers/screenshot_helper.rb b/app/helpers/screenshot_helper.rb index 1cd326e..185ef68 100644 --- a/app/helpers/screenshot_helper.rb +++ b/app/helpers/screenshot_helper.rb @@ -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 diff --git a/app/views/screenshot/single.html.erb b/app/views/screenshot/single.html.erb index 40a04eb..780bae9 100644 --- a/app/views/screenshot/single.html.erb +++ b/app/views/screenshot/single.html.erb @@ -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) %>
-
- <%= image_tag @fpath , :width => width , :height => height%> +
+ <%= image_tag @fpath , :width => size[width] , :height => size[height] %>
\ No newline at end of file