Skip to content

Instantly share code, notes, and snippets.

@track8
Created February 6, 2013 14:49
Show Gist options
  • Save track8/4723000 to your computer and use it in GitHub Desktop.
Save track8/4723000 to your computer and use it in GitHub Desktop.
>> rackup
# config.ru
require 'rack'
require 'gdk_pixbuf2'
class AvatarClone
def call(env)
request = Rack::Request.new(env)
case request.request_method
when 'GET'
begin
filename = "./avatar/#{request.path.split('/')[1]}.jpg"
return [200,
{'Content-type' => 'image/jpeg'},
[Gdk::Pixbuf.new(filename).scale(80, 80).save_to_buffer("jpeg")]]
rescue
Rack::Response.new("Not Found", 404)
end
else
Rack::Response.new("Bad Request", 400)
end
end
end
run AvatarClone.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment