Skip to content

Instantly share code, notes, and snippets.

@tungd
Last active December 18, 2015 15:18
Show Gist options
  • Save tungd/5803029 to your computer and use it in GitHub Desktop.
Save tungd/5803029 to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
gem "sinatra"
gem "puma"
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
@tungd
Copy link
Author

tungd commented Jun 18, 2013

Setup:

gem install sinatra puma #or bundle install
ruby lorempixel.rb

Go to http://localhost:5000/200/300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment