Skip to content

Instantly share code, notes, and snippets.

@ismasan
Last active December 17, 2015 01:49
Show Gist options
  • Save ismasan/5531416 to your computer and use it in GitHub Desktop.
Save ismasan/5531416 to your computer and use it in GitHub Desktop.
require 'bundler/setup'
require 'sinatra/base'
require 'dragonfly'
# http://cdn.bootic.net/224/original/25369-eyeglasses.jpg
class App < Sinatra::Base
set :images_app, (
Dragonfly[:images].configure_with(:imagemagick).tap do |app|
app.cache_duration = 3600*24*365*3
end
)
set :error_images_app, (
Dragonfly[:error_images].configure_with(:imagemagick).tap do |app|
app.cache_duration = 1800 # half hour
end
)
get '/r/:shop_id/:size/:image_path' do |shop_id, size, image_path|
origin_url = "http://cdn.bootic.net/#{shop_id}/original/#{image_path}"
begin
#image = settings.images_app.fetch_url(origin_url)
image = settings.images_app.fetch_file("./#{image_path}")
image.image?
rescue Exception => e
image = settings.error_images_app.fetch_file('./404.png')
# Notify exception
ensure
image.thumb! "#{size}#"
end
puts "serving #{size}"
image.to_response(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment