-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver_app.js
112 lines (94 loc) · 3.08 KB
/
server_app.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Module dependencies.
*/
var nowjs = require("now");
var express = require('express')
, routes = require('./routes');
var app = module.exports = express.createServer();
var gm = require('gm')
, dir = __dirname + '/imgs'
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: 'your secret here' }));
app.use(app.router);
app.use(express.static(__dirname + '/imgs'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
app.listen(3000, function(){
console.log("Express server listening in %s mode", app.settings.env);
});
var everyone = nowjs.initialize(app);
everyone.now.performEffect = function(img,effect){
console.log("------- performing effect --- "+effect+ " on image "+img);
if(effect == 'blur'){
blur(img);
} else if(effect == 'draw'){
draw(img);
} else if(effect == 'rotate'){
rotate(img);
} else if(effect == 'resize'){
resize(img);
}
};
function blur(img){
gm(dir + '/'+img).blur(19, 10).write(dir + '/blurred.jpg', function(err){
if (err) return console.dir(arguments)
console.log(this.outname + ' created :: ' + arguments[3])
everyone.now.receiveOutput("msg", "blurred.jpg");
//require('child_process').exec('open ' + dir + '/galaxy_blurred.jpg');
});
}
function draw(img){
gm(dir + '/'+img)
.stroke("red", 7)
.fill("#ffffffbb")
.drawLine(20, 10, 50, 40)
.fill("#2c2")
.stroke("blue", 1)
.drawRectangle(40, 10, 50, 100)
.drawRectangle(60, 10, 70, 20, 3)
.drawArc(80, 10, 90, 20, 0, 180)
.drawEllipse(105, 15, 3, 5)
.drawCircle(125, 15, 120, 120)
.drawPolyline([140, 10], [143, 13], [145, 13], [147, 15], [145, 17], [143, 19])
.drawPolygon([160, 10], [163, 13], [165, 13], [167, 15], [165, 17], [163, 19])
.drawBezier([180, 10], [183, 13], [185, 13], [187, 15], [185, 17], [183, 19])
.fontSize(68)
.stroke("#efe", 2)
.fill("#888")
.write(dir + '/drawing.jpg', function(err){
if (err) return console.dir(arguments)
console.log(this.outname + ' created :: ' + arguments[3])
everyone.now.receiveOutput("msg", "drawing.jpg");
})
}
function rotate(img){
gm(dir + '/'+img)
.rotate('red', -30)
.write(dir + '/rotate.jpg', function(err){
if (err) return console.dir(arguments)
console.log(this.outname + " created :: " + arguments[3])
everyone.now.receiveOutput("msg", "rotate.jpg");
})
}
function resize(img){
gm(dir + '/'+img)
.thumb(50, 50, dir + '/thumb.jpg', function(err){
if (err) return console.dir(arguments)
console.log(this.outname + " created :: " + arguments[3])
everyone.now.receiveOutput("msg", "thumb.jpg");
})
}
// everyone.now.receiveOutput("msg", "\n ---- waiting for compiler ----");