Skip to content

Commit d039c01

Browse files
author
unbuntu server
committed
complete fonts
1 parent 351e33f commit d039c01

File tree

5 files changed

+166
-34
lines changed

5 files changed

+166
-34
lines changed

app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var koa = require('koa'),
55
url = require('url'),
66
router = require('koa-route'),
77
views = require('co-views'),
8-
ga = require('./lib/generateAvatar');
8+
ga = require('./lib/generateAvatar'),
9+
ft = require('./lib/fontStyle');
910

1011
// custom 401 handling
1112

@@ -46,7 +47,7 @@ var render= views(__dirname + '/views', { map: { html: 'swig' }});
4647

4748
function* avatar(name){
4849
var parseUrl = url.parse(decodeURI(this.request.url),true);
49-
var filename = yield ga(name.toString(),parseUrl.query.size);
50+
var filename = yield ga(name.toString(),parseUrl.query.size,parseUrl.query.font);
5051
global.reatime.amount += 1;
5152
io.emit('notify', { item: global.reatime});
5253
this.type = 'image/png';
@@ -55,7 +56,7 @@ function* avatar(name){
5556

5657

5758
function* index(){
58-
this.body = yield render('index.jade', { });
59+
this.body = yield render('index.jade', {fonts: ft.fonts, nowcount: global.reatime.amount});
5960
}
6061

6162
app.use(router.get('/', index));

lib/fontStyle.js

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,104 @@
1-
var fonts =[
2-
{
3-
name: 'SinCycle',
1+
var fonts ={
2+
abduction: {
3+
path: 'Abduction.ttf',
4+
name: 'abduction'
5+
},
6+
adisport: {
7+
path: 'ADISPORT.TTF',
8+
name: 'adisport'
9+
},
10+
aura: {
11+
path: 'Aura-Regular.ttf',
12+
name: 'aura'
13+
},
14+
bladrmf: {
15+
path: 'bladrmf.ttf',
16+
name: 'bladrmf'
17+
},
18+
caricature: {
19+
path: 'caricature.ttf',
20+
name: 'caricature'
21+
},
22+
cityscape: {
23+
path: 'cityscape_font.ttf',
24+
name: 'cityscape'
25+
},
26+
collage: {
27+
path: 'Collage_annonymus.ttf',
28+
name: 'collage'
29+
},
30+
commonv23di: {
31+
path: 'Commonv23di.ttf',
32+
name: 'commonv23di'
33+
},
34+
d3cubism: {
35+
path: 'D3Cubism.ttf',
36+
name: 'd3cubism'
37+
},
38+
fh0905: {
39+
path: 'FH0905.TTF',
40+
name: 'fh0905'
41+
},
42+
graffonti: {
43+
path: 'graffonti_3d_drop__fontvir_us_.ttf',
44+
name: 'graffonti'
45+
},
46+
guardianpi: {
47+
path: 'guardianpi.ttf',
48+
name: 'guardianpi'
49+
},
50+
kingthings: {
51+
path: 'Kingthings_Extortion.ttf',
52+
name: 'kingthings'
53+
},
54+
movie: {
55+
path: 'Movie_Filmstrip.ttf',
56+
name: 'movie'
57+
},
58+
sketch: {
59+
path: 'Sketch_Block.ttf',
60+
name: 'sketch'
61+
},
62+
snowcaps: {
63+
path: 'SNOWCAPS.TTF',
64+
name: 'snowcaps'
65+
},
66+
spincycle: {
467
path: 'spincycle_ot.otf',
5-
stroke: 0
68+
name: 'spincycle'
69+
},
70+
terminator: {
71+
path: 'terminator_real_nfi.ttf',
72+
name: 'terminator'
73+
},
74+
thickhead: {
75+
path: 'Thickhead_Dark.ttf',
76+
name: 'thickhead'
77+
},
78+
urban: {
79+
path: 'UrbanJungleDEMO.ttf',
80+
name: 'urban'
81+
},
82+
vpsgdh: {
83+
path: 'VPSGDH.TTF',
84+
name: 'vpsgdh'
85+
},
86+
willywonka: {
87+
path: 'WillyWonka.ttf',
88+
name: 'willywonka'
689
}
7-
]
90+
}
891

9-
var fontStyle = function(fontIndex){
10-
return colors[fontIndex] || fonts[0];
92+
var fontStyle = function(name){
93+
return fonts[name] || {
94+
path: 'deault',
95+
name: 'deault'
96+
}
1197
}
1298

1399

14100

15-
module.exports = fontStyle;
101+
module.exports = {
102+
fontStyle: fontStyle,
103+
fonts: fonts
104+
};

lib/generateAvatar.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ var co = require('co'),
44
gm = require('gm').subClass({imageMagick: true}),
55
fnv = require('fnv-plus'),
66
pinyin = require("pinyin"),
7+
ft = require('./fontStyle'),
78
bc = require('./bgColor');
89

910

10-
var gmp = function gmo(filepath,text,bgcolor,size){
11+
var gmp = function(filepath,text,bgcolor,size,font){
1112
var deferred = Q.defer();
1213
gm(200, 200, bgcolor)
1314
.encoding("Unicode")
1415
.fontSize(100)
1516
.fill("rgba(255,255,255,0.3)")
16-
.stroke("rgba(255,255,255,0.5)",0)
17-
.font("./fonts/d-puntillas-F-Tiptoes-squid.ttf")
17+
.stroke("rgba(255,255,255,0.3)",1)
18+
.font("./fonts/" + font.path)
1819
.drawText(0, 0, text,'Center')
1920
.resize(size)
2021
.write(filepath, deferred.resolve);
@@ -23,25 +24,33 @@ var gmp = function gmo(filepath,text,bgcolor,size){
2324

2425

2526

26-
var generateAvatar = function* (uid,size){
27+
var generateAvatar = function* (uid,size,font){
28+
// -size
2729
var range = [50,100,200]
2830
size = parseInt(size || 50);
2931
if (range.indexOf(size) < 0) {
3032
size = 50;
3133
};
34+
35+
//- 字体
36+
font = ft.fontStyle(font);
37+
38+
39+
3240
uid = (uid == '[object Generator]' ? 'A' : uid);
3341

3442
uid = pinyin(uid)[0][0]
3543

3644

3745
var flag = fnv.hash(uid).str();
3846
var bgcoloIndex = flag[flag.length - 1].toUpperCase();
39-
var filepath = "avatars/" + uid[0].toUpperCase() + "-" + bgcoloIndex + "-" + size + ".png";
47+
48+
var filepath = "avatars/" + uid[0].toUpperCase() + "-" + bgcoloIndex + "-" + size + "-" + font.name +".png";
4049

4150
var exists = yield fs.exists(filepath);
4251

4352
if (!exists){
44-
yield gmp(filepath,uid[0].toUpperCase(),bc(bgcoloIndex),size)
53+
yield gmp(filepath,uid[0].toUpperCase(),bc(bgcoloIndex),size,font)
4554
}
4655

4756
return filepath;

now.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1126
1+
8134

views/index.jade

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ block con
66
.banner{background-color: #E0CEB3; color:#8C7A5E; padding: 50px 0;text-align: center;}
77
.banner h1{margin: 0; font-size: 150px;}
88
.container{width: 99%; max-width: 1000px; margin: 0 auto}
9-
img.item{margin: 20px; box-shadow: 1px 1px 5px #BEBEBE;}
9+
img.item{margin: 20px; box-shadow: 1px 1px 5px #BEBEBE; border-radius: 100%}
1010
#name-txt{border: none; padding: 15px; width: 200px; margin: 50px 0; outline: none; border-radius: 100px; font-size: 20px; text-align:center;}
1111
a{text-decoration: none}
1212
a#url{ display: inline-block; background-color: #EEE; padding: 10px 20px; opacity: 0.5; border-radius: 100px; color: #150E03}
@@ -21,6 +21,8 @@ block con
2121
.usage{background-color: #F2BB62; padding: 50px 0; overflow: hidden; color:#025360; text-align:center;color: #A86E10}
2222
.usage .featitle{color: #A86E10}
2323
#amount{font-size: 50px; margin: 0 10px; }
24+
table.params{width: 100%;border-right: #F7AB31 3px solid;border-top: #F7AB31 3px solid;}
25+
table.params td,table.params th{min-width: 100px;border-left: #F7AB31 3px solid; border-bottom: #F7AB31 3px solid; padding: 10px;}
2426

2527

2628
div.banner
@@ -32,7 +34,7 @@ block con
3234
span times
3335
input#name-txt(type="text" placeholder="Nickname")
3436
p: img#preview(src="http://svpa.awesomes.cn/avatar?size=200")
35-
p: a#url(href="http://svpa.awesomes.cn/avatar?size=200" target="_blank") http://svpa.awesomes.cn/avatar?size=200
37+
p: a#url(href="http://svpa.awesomes.cn/avatar?size=200" target="_blank") http://svpa.awesomes.cn/avatar?size=200&font=default
3638
div.feature
3739
div.container
3840
h1.featitle Features
@@ -64,23 +66,41 @@ block con
6466
span http://svpa.awesomes.cn/avatar/[
6567
strong nickname
6668
span ]?size=[
67-
stron 100
69+
strong 100
70+
span ]&font=[
71+
strong default
6872
span ]
6973
h3 method
7074
p Get & Post
7175
h3 nickname
7276
p required. Support both English and Chinese
73-
h3 size
74-
p
75-
span optional. The value can be one of [
76-
strong 50,100,200
77-
span ]. Default is
78-
strong 50
77+
h3 params
78+
table.params(cellspacing="0")
79+
tr
80+
th Name
81+
th Required
82+
th Default
83+
th Description
84+
tr
85+
td size
86+
td optional
87+
td 50
88+
td The size of the avatar(both width and height is the same.The units is px) The value can be one of [50,100,200]
89+
90+
tr
91+
td font
92+
td optional
93+
td default
94+
td The font of the letter text.(avalible fonts is below)
95+
96+
7997

8098
div.container.demos
81-
h1.featitle(style="color: #469DAC") Some Avatars...
82-
- for item in ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',0,1,2,3,4,5,6,7,8,9]
83-
img.item(src="http://192.168.254.128:8080/avatar/#{item}121212111?size=100")
99+
h1.featitle(style="color: #469DAC") #{fonts.length} Avatar Fonts...
100+
-for font in fonts
101+
h3.featitle #{font.name}
102+
- for item in ['a','b','c','d','e','f','g']
103+
img.item(src="http://192.168.141.128:8080/avatar/#{item}"+font.name+"?size=100&font="+font.name)
84104

85105
div.footer
86106
p
@@ -96,15 +116,28 @@ block con
96116
script(type='text/javascript').
97117
$(function(){
98118
$("#name-txt").keyup(function(){
99-
var url = "http://svpa.awesomes.cn/avatar/"+$(this).val()+"?size=200";
119+
var url = "http://svpa.awesomes.cn/avatar/"+$(this).val()+"?size=200&font=default";
100120
$("#url").html(url).attr("href",url);
101121
$("#preview").attr("src",url)
102122
})
103123

124+
125+
var now = 0;
126+
var timer = setInterval(function(){
127+
$("#amount").html(now);
128+
now = now + 10;
129+
if(now >= #{nowcount}){
130+
clearInterval(timer);
131+
$("#amount").html(#{nowcount});
132+
set_socket();
133+
}
134+
},1)
135+
136+
})
104137

138+
function set_socket(){
105139
var socket = io('http://svpa.awesomes.cn');
106140
socket.on('notify', function(data){
107-
$("#amount").html(data.item.amount)
108-
console.log(data)
141+
$("#amount").html(data.item.amount);
109142
});
110-
})
143+
}

0 commit comments

Comments
 (0)