Created
August 5, 2013 08:21
-
-
Save lexrus/6154257 to your computer and use it in GitHub Desktop.
A tiny Sinatra app turns URL to QRCode.
This file contains 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' | |
require 'pngqr' | |
require 'slim' | |
require 'stylus' | |
require 'stylus/tilt' | |
set :site_name => 'QRCode.rb' | |
set :server => %w[thin] | |
set :port => 9494 | |
#set :dump_errors => true | |
get '/' do | |
site_name = settings.site_name | |
slim <<HTML | |
doctype html | |
head | |
title #{site_name} | |
styl: | |
body | |
text-align center | |
width 200 | |
input | |
font 16px Helvetica, Arial, sans-serif | |
padding 0.5em | |
body | |
h1 #{site_name} | |
form action="encode" | |
input.url name="q" placeholder="URL" | |
input type="submit" | |
HTML | |
end | |
get '/encode' do | |
url = request['q'] | |
if url.nil? or url.empty? | |
status 401 | |
else | |
Pngqr.encode(url, '/tmp/qr.png') | |
png = File::read('/tmp/qr.png') | |
headers 'Content-Type' => 'image/png' | |
body png | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment