forked from totaljs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.js
More file actions
63 lines (49 loc) · 1.92 KB
/
Copy pathdefault.js
File metadata and controls
63 lines (49 loc) · 1.92 KB
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
var Path = require('path');
exports.install = function() {
F.route('/', view_index);
// the number is maximum data receive
F.route('/', view_index, ['upload'], 100); // max 100 kB
};
function view_index() {
var self = this;
var model = { info: '...' };
var file = self.files[0];
if (self.files.length === 0 || !file.isImage()) {
self.view('index', model);
return;
}
// file.isAudio();
// file.isVideo();
// file.isImage();
model.info = file.filename + ' ({0} kB) - {1}x{2}'.format(Math.floor(file.length / 1024, 2), file.width, file.height);
// =============================
// $ brew install graphicsmagick
// =============================
var filename = F.path.public('upload.jpg');
// Documentation: http://docs.totaljs.com/FrameworkImage/
var image = file.image(); // this is equivalent to require('partail.js/image').init([useImageMagick]);
// require('total.js/image').init(filename, [useImageMagick]);
// file.image([useImageMagick]);
// image.identify(function(err, info) { info.width, info.heigth });
// image.resize(w, h, options);
// image.resizeCenter(w, h); :: resize(w, h, '^').align('center center').crop(w, h);
// image.crop(w, h, x, y);
// image.scale(w, h);
// image.quality(percentage);
// image.align(type); :: left-top left-bottom left-center right-top right-bottom right-center top-center bottom-center center-center
// image.blur(radius);
// image.normalize();
// image.rotate(deg);
// image.flip();
// image.flop();
// image.minify();
// image.grayscale();
// image.background(color);
// image.sepia();
// image.command(command, [priority]);
// IMPORTANT: see here https://github.com/petersirka/total.js/tree/master/examples/routing
image.resizeCenter(300, 300).save(filename, function(err) {
model.url = '<div><img src="/{0}?ts={1}" width="300" height="300" alt="Uploaded image" /></div><br />'.format(U.getName(filename), new Date().getTime());
self.view('index', model);
});
}