added image file

v1.18.x
Baris Soner Usakli 11 years ago
parent 26849ba2b7
commit 20ec8ca768

@ -0,0 +1,46 @@
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;
Loading…
Cancel
Save