Skip to content

Instantly share code, notes, and snippets.

@russ
Created October 14, 2008 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russ/16728 to your computer and use it in GitHub Desktop.
Save russ/16728 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'RMagick'
ROOT_PATH = File.expand_path(File.dirname(__FILE__))
get '/*' do
resize_image(params[:splat].first)
redirect("/#{params[:splat].first}")
end
def resize_image(request_uri, filename = nil)
path = File.dirname("#{ROOT_PATH}/public/#{request_uri}")
file = /(\w+)\.(jpg|jpeg|png|gif)$/.match(request_uri)
Magick::ImageList::new(path + '/original.jpg').change_geometry("#{file[1]}>") do |cols, rows, img|
img.resize!(cols, rows)
img.write("#{path}/#{file[1]}.#{file[2]}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment