Last active
December 18, 2015 15:18
-
-
Save tungd/5803029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "sinatra" | |
gem "puma" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
set :port, ENV['PORT'] || 5000 | |
get /(.+)/ do | |
p = params[:captures].split(/\/|\./) | |
# Available params: width/height/category.format | |
width = p.empty? ? 600 : p.shift | |
height = p.empty? ? 400 : p.shift | |
category = p.empty? ? "**" : p.shift | |
format = p.empty? ? 'jpeg' : p.shift | |
# puts [width, height, category, format] | |
# TODO: crop the image | |
status 200 | |
headers "Content-Type" => "image/#{format}" | |
File.read Dir["img/#{category}/*.#{format}"].shuffle.first | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup:
Go to http://localhost:5000/200/300