-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreator.rb
73 lines (62 loc) · 2.22 KB
/
creator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'RMagick'
require 'sinatra'
include Magick
get '/' do
name = params['name'] ||= "Name"
name.sub!(name.chars.first,name.chars.first.upcase)
erb :index, :locals => { :name => name.gsub('TEDx','') }
end
get '/TEDx:name:type.png' do
content_type 'application/force-download'
@type = params['type']
def tedx(color, height, name_x, name_y, independently_x, independently_y, organized_x, organized_y)
max_chars = 20;
name = params['name']
width = name.length*110
if name_x == 420
width = width + 420
end
if (organized_x == 395 && width < 860)
width = 860
elsif (width < 530)
width = 530
end
fill = (color == "w" ? "white" : "black")
image = Magick::ImageList.new
image.new_image(width, height) {self.background_color = fill}
image = image.composite(ImageList.new("tedx#{color}.png"), Magick::NorthWestGravity, 30, 30, Magick::AtopCompositeOp)
image = image.composite(ImageList.new("independently#{color}.png"), Magick::SouthWestGravity, independently_x, independently_y, Magick::AtopCompositeOp)
image = image.composite(ImageList.new("organized#{color}.png"), Magick::NorthWestGravity, organized_x, organized_y, Magick::AtopCompositeOp)
text = Magick::Draw.new
text.font_family = 'helvetica'
text.pointsize = 144
text.kerning = 0
text.text_antialias = true
text.gravity = Magick::WestGravity
text.annotate(image, 110,1,name_x - 20,name_y - 37, name) {
self.fill = (fill == "white" ? "black" : "white")
}
image.format = "png"
return image.to_blob
end
# color, height, name_x, name_y, independently_x, independently_y, organized_x, organized_y
# corrections in place of originals
case @type
when '1'
tedx("w", 240, 420, 136, 32, 162-130, 395, 165)
when '2'
tedx("w", 290, 420, 136, 32, 162-80, 32, 214)
when '3'
tedx("w", 370, 30+18, 267, 32, 293-259, 395, 293)
when '4'
tedx("w", 420, 30+18, 267, 32, 293-213, 32, 345)
when '5'
tedx("b", 240, 420, 136, 32, 162-130, 395, 165)
when '6'
tedx("b", 290, 420, 136, 32, 162-80, 32, 214)
when '7'
tedx("b", 370 + 10, 30+18, 267, 32, 293-249, 395, 293)
else
tedx("b", 420, 30+18, 267, 32, 293-213, 32, 345)
end
end