Sha256: 0f8e5075969dff52e32ba8774d3f6ef32603fcf42c547074ead9bd68eb472ca7

Contents?: true

Size: 666 Bytes

Versions: 10

Compression:

Stored size: 666 Bytes

Contents

ROOT = File.expand_path(File.dirname(__FILE__))

require 'sinatra'
require ROOT + '/../lib/dimension'

get '/' do
  images = Dir.glob(File.join(ROOT, 'assets') + '/*')
  links = images.map do |i|
    name = File.basename(i)
    "<a href='/images/#{name}'>#{name}</a>"
  end
  '<ul><li>' + links.join('</li><li>') + '</li></ul>'
end

get '/images/:file' do
  file = File.join(ROOT, 'assets', params[:file])

  if params[:geometry].nil?
    puts "Returning original file: #{file}"
    return send_file file
  end

  begin
    thumb = Dimension.open(file)
  rescue => e
    return e.message
  end

  thumb.generate(params[:geometry]) do
    thumb.to_response
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dimension-0.1.4 examples/sinatra.rb
dimension-0.1.3 examples/sinatra.rb
dimension-0.1.2 examples/sinatra.rb
dimension-0.1.1 examples/sinatra.rb
dimension-0.0.7 examples/sinatra.rb
dimension-0.0.6 examples/sinatra.rb
dimension-0.1.0 examples/sinatra.rb
dimension-0.0.5 examples/sinatra.rb
dimension-0.0.4 examples/sinatra.rb
dimension-0.0.2 examples/sinatra.rb