From b3ac631a556d912d590909406a5696142a518844 Mon Sep 17 00:00:00 2001 From: Andrew Davidson Date: Thu, 29 Oct 2009 03:55:22 -0700 Subject: [PATCH] adding basic support for screenshots. --- app/controllers/screenshot_controller.rb | 4 +++- app/views/screenshot/single.html.erb | 24 ++++++++++++++++++++++++ config/routes.rb | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/controllers/screenshot_controller.rb b/app/controllers/screenshot_controller.rb index d4655c4..8028816 100644 --- a/app/controllers/screenshot_controller.rb +++ b/app/controllers/screenshot_controller.rb @@ -10,7 +10,9 @@ class ScreenshotController < ApplicationController end def single - @screenshot = "x" + @fpath = "screenshots/" + params[:filename] + fabsolute = RAILS_ROOT + "/public/images/screenshots/" + params[:filename] + @fsize = IO.read(fabsolute)[0x10..0x18].unpack('NN') respond_to do |format| format.html diff --git a/app/views/screenshot/single.html.erb b/app/views/screenshot/single.html.erb index e69de29..40a04eb 100644 --- a/app/views/screenshot/single.html.erb +++ b/app/views/screenshot/single.html.erb @@ -0,0 +1,24 @@ +<% +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 + +%> + +
+
+ <%= image_tag @fpath , :width => width , :height => height%> +
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ab746cb..6194d11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,7 +43,7 @@ ActionController::Routing::Routes.draw do |map| map.connect 'f/:id', :controller => "flickr", :action => "photo" map.connect 's/i', :controller => "screenshot", :action => "index" - map.connect 's/:id', :controller => "screenshot", :action => "single" + map.connect 's/:filename', :controller => "screenshot", :action => "single", :requirements => { :filename => /.*/ } map.connect 'i/:action', :controller => "info"