You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
11 years ago
|
|
||
|
var fs = require('fs'),
|
||
|
imagemagick = require('node-imagemagick'),
|
||
|
meta = require('./meta');
|
||
|
|
||
|
var image = {};
|
||
|
|
||
|
image.resizeImage = function(path, extension, width, height, callback) {
|
||
|
function done(err, stdout, stderr) {
|
||
|
callback(err);
|
||
|
}
|
||
|
|
||
|
if(extension === '.gif') {
|
||
|
imagemagick.convert([path, '-coalesce', '-repage', '0x0', '-crop', width+'x'+height+'+0+0', '+repage', 'uploadPath'], done);
|
||
|
} else {
|
||
|
imagemagick.crop({
|
||
|
srcPath: path,
|
||
|
dstPath: path,
|
||
|
width: width,
|
||
|
height: height
|
||
|
}, done);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
image.convertImageToPng = function(path, extension, callback) {
|
||
|
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
||
|
if(convertToPNG && extension !== '.png') {
|
||
|
imagemagick.convert([path, 'png:-'], function(err, stdout) {
|
||
|
if(err) {
|
||
|
return callback(err);
|
||
|
}
|
||
|
|
||
|
fs.writeFile(path, stdout, 'binary', callback);
|
||
|
});
|
||
|
} else {
|
||
|
callback();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
image.convertImageToBase64 = function(path, callback) {
|
||
|
fs.readFile(path, function(err, data) {
|
||
|
callback(err, data ? data.toString('base64') : null);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
module.exports = image;
|