зеркало из https://github.com/mozilla/CSOL-site.git
Thumbnail generators
This commit is contained in:
Родитель
afaf26ce92
Коммит
2411e212ac
|
@ -0,0 +1,54 @@
|
|||
var exec = require('child_process').exec;
|
||||
var im = require('imagemagick');
|
||||
var path = require('path');
|
||||
|
||||
var imageThumb = function (input, output, format, width, height, callback) {
|
||||
if (typeof height === 'function') {
|
||||
callback = height;
|
||||
height = null;
|
||||
}
|
||||
|
||||
return im.crop({
|
||||
srcPath: input,
|
||||
dstPath: output,
|
||||
width: width,
|
||||
height: height,
|
||||
format: format
|
||||
}, callback);
|
||||
}
|
||||
|
||||
var videoThumb = function (input, output, format, width, height, callback) {
|
||||
if (typeof height === 'function') {
|
||||
callback = height;
|
||||
height = '?';
|
||||
}
|
||||
|
||||
function escapePath (str) {
|
||||
return '"' + path.normalize(str.replace(/(["\s'$`\\])/g,'\\$1')) + '"';
|
||||
}
|
||||
|
||||
if (output)
|
||||
output = escapePath(output);
|
||||
else
|
||||
output = 'pipe:' + format;
|
||||
|
||||
// Ideally, we'd be doing this via some library, but I'm yet to find one
|
||||
// that seems to allow for buffer output, rather than saving to file.
|
||||
|
||||
var args = [
|
||||
'-loglevel', 0, // Turn off output
|
||||
'-i', escapePath(input), // Use input file
|
||||
'-vframes', 1, // Use only one frame
|
||||
'-ss', '00:00:02', // Taken from two seconds in
|
||||
'-s', width + 'x' + height, // Thumbnail dimensions
|
||||
'-f', 'image2', // Set commands file
|
||||
output // Output
|
||||
];
|
||||
|
||||
var cmd = 'ffmpeg ' + args.join(' ');
|
||||
|
||||
return exec(cmd, {encoding: 'binary'}, callback);
|
||||
}
|
||||
|
||||
module.exports.image = imageThumb;
|
||||
module.exports.video = videoThumb;
|
|
@ -8,6 +8,7 @@
|
|||
"bcrypt": "~0.7.5",
|
||||
"connect-flash": "~0.1.1",
|
||||
"express": "~3.1.0",
|
||||
"imagemagick": "~0.1.3",
|
||||
"knox": "~0.8.2",
|
||||
"mysql": "~2.0.0-alpha7",
|
||||
"nunjucks": "~0.1.8a",
|
||||
|
|
Загрузка…
Ссылка в новой задаче