Skip to content
Newer
Older
100644 52 lines (40 sloc) 1.15 KB
c003dff @igrigorik heroku app
authored Jan 15, 2011
1 require 'rubygems'
5101389 @igrigorik sinatra app
authored Jan 15, 2011
2 require 'sinatra'
3 require 'helper'
4
c003dff @igrigorik heroku app
authored Jan 15, 2011
5 def render_image(text, from)
5101389 @igrigorik sinatra app
authored Jan 15, 2011
6 quote = Image.read("quote.png").first
7
8 RVG::dpi = 72
9
c003dff @igrigorik heroku app
authored Jan 15, 2011
10 bg = RVG.new(800.px, 480.px) do |canvas|
5101389 @igrigorik sinatra app
authored Jan 15, 2011
11 canvas.background_fill = 'black'
12 end.draw
13
c003dff @igrigorik heroku app
authored Jan 15, 2011
14 text = render_cropped_text(text, 620, 430) do |img|
5101389 @igrigorik sinatra app
authored Jan 15, 2011
15 img.fill = "#ffffff" # font color
16 img.background_color = "transparent"
17 img.pointsize = 23
18 img.antialias = true
19 end
20
c003dff @igrigorik heroku app
authored Jan 15, 2011
21 src = render_cropped_text(from, 620, 40) do |img|
5101389 @igrigorik sinatra app
authored Jan 15, 2011
22 img.fill = "#cccccc" # font color
23 img.background_color = "transparent"
24 img.pointsize = 18
25 img.antialias = true
26 end
27
28 quote.page = Rectangle.new(quote.rows,quote.columns,15,30)
29 text.page = Rectangle.new(text.rows,text.columns,105,65)
30 src.page = Rectangle.new(src.rows,src.columns,105,430)
31
32 r = ImageList.new
33 r << bg << quote << text << src
c003dff @igrigorik heroku app
authored Jan 15, 2011
34 end
35
36 get "/" do
37 erb :index
38 end
5101389 @igrigorik sinatra app
authored Jan 15, 2011
39
c003dff @igrigorik heroku app
authored Jan 15, 2011
40 get "/quote" do
5101389 @igrigorik sinatra app
authored Jan 15, 2011
41 content_type 'image/png'
c003dff @igrigorik heroku app
authored Jan 15, 2011
42
43 r = render_image(params[:quote], params[:source])
5101389 @igrigorik sinatra app
authored Jan 15, 2011
44 r.flatten_images.to_blob {|i| i.format = 'PNG'}
45 end
c003dff @igrigorik heroku app
authored Jan 15, 2011
46
47 post "/quote" do
48 content_type 'image/png'
49
50 r = render_image(params[:quote], params[:source])
51 r.flatten_images.to_blob {|i| i.format = 'PNG'}
52 end
Something went wrong with that request. Please try again.