2014-03-05 23:00:27 -05:00
|
|
|
'use strict';
|
2014-02-09 00:34:05 -05:00
|
|
|
|
|
|
|
|
var fs = require('fs'),
|
2015-05-30 20:04:42 +02:00
|
|
|
lwip = require('lwip');
|
2014-02-09 00:34:05 -05:00
|
|
|
|
|
|
|
|
var image = {};
|
|
|
|
|
|
|
|
|
|
image.resizeImage = function(path, extension, width, height, callback) {
|
2015-05-30 20:04:42 +02:00
|
|
|
lwip.open(path, function(err, image) {
|
|
|
|
|
image.batch()
|
|
|
|
|
.cover(width, height)
|
2014-04-27 17:40:39 -04:00
|
|
|
.crop(width, height)
|
2015-05-30 20:04:42 +02:00
|
|
|
.writeFile(path, function(err) {
|
|
|
|
|
callback(err)
|
|
|
|
|
})
|
|
|
|
|
});
|
2014-02-09 00:34:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
image.convertImageToPng = function(path, extension, callback) {
|
2014-08-08 17:30:37 -04:00
|
|
|
if(extension !== '.png') {
|
2015-05-30 20:04:42 +02:00
|
|
|
lwip.open(path, function(err, image) {
|
2014-03-05 23:00:27 -05:00
|
|
|
if (err) {
|
2014-02-09 00:34:05 -05:00
|
|
|
return callback(err);
|
|
|
|
|
}
|
2015-05-30 20:04:42 +02:00
|
|
|
image.writeFile(path, 'png', callback)
|
2014-02-09 00:34:05 -05:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
image.convertImageToBase64 = function(path, callback) {
|
|
|
|
|
fs.readFile(path, function(err, data) {
|
|
|
|
|
callback(err, data ? data.toString('base64') : null);
|
|
|
|
|
});
|
2014-03-05 23:00:27 -05:00
|
|
|
};
|
2014-02-09 00:34:05 -05:00
|
|
|
|
2014-04-10 20:31:57 +01:00
|
|
|
module.exports = image;
|