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.
nodebb/src/image.js

39 lines
773 B
JavaScript

11 years ago
'use strict';
11 years ago
var fs = require('fs'),
lwip = require('lwip');
11 years ago
var image = {};
image.resizeImage = function(path, extension, width, height, callback) {
lwip.open(path, function(err, image) {
image.batch()
.cover(width, height)
11 years ago
.crop(width, height)
.writeFile(path, function(err) {
callback(err)
})
});
11 years ago
};
image.convertImageToPng = function(path, extension, callback) {
if(extension !== '.png') {
lwip.open(path, function(err, image) {
11 years ago
if (err) {
11 years ago
return callback(err);
}
image.writeFile(path, 'png', callback)
11 years ago
});
} else {
callback();
}
};
image.convertImageToBase64 = function(path, callback) {
fs.readFile(path, function(err, data) {
callback(err, data ? data.toString('base64') : null);
});
11 years ago
};
11 years ago
module.exports = image;