|
|
@ -1,11 +1,22 @@
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var fs = require('fs'),
|
|
|
|
var fs = require('fs'),
|
|
|
|
lwip = require('lwip');
|
|
|
|
lwip = require('lwip'),
|
|
|
|
|
|
|
|
plugins = require('./plugins');
|
|
|
|
|
|
|
|
|
|
|
|
var image = {};
|
|
|
|
var image = {};
|
|
|
|
|
|
|
|
|
|
|
|
image.resizeImage = function(path, extension, width, height, callback) {
|
|
|
|
image.resizeImage = function(path, extension, width, height, callback) {
|
|
|
|
|
|
|
|
if (plugins.hasListeners('filter:image.resize')) {
|
|
|
|
|
|
|
|
plugins.fireHook('filter:image.resize', {
|
|
|
|
|
|
|
|
path: path,
|
|
|
|
|
|
|
|
extension: extension,
|
|
|
|
|
|
|
|
width: width,
|
|
|
|
|
|
|
|
height: height
|
|
|
|
|
|
|
|
}, function(err, data) {
|
|
|
|
|
|
|
|
callback(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
lwip.open(path, function(err, image) {
|
|
|
|
lwip.open(path, function(err, image) {
|
|
|
|
image.batch()
|
|
|
|
image.batch()
|
|
|
|
.cover(width, height)
|
|
|
|
.cover(width, height)
|
|
|
@ -14,18 +25,24 @@ image.resizeImage = function(path, extension, width, height, callback) {
|
|
|
|
callback(err)
|
|
|
|
callback(err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
image.convertImageToPng = function(path, extension, callback) {
|
|
|
|
image.normalise = function(path, extension, callback) {
|
|
|
|
if(extension !== '.png') {
|
|
|
|
if (plugins.hasListeners('filter:image.normalise')) {
|
|
|
|
|
|
|
|
plugins.fireHook('filter:image.normalise', {
|
|
|
|
|
|
|
|
path: path,
|
|
|
|
|
|
|
|
extension: extension
|
|
|
|
|
|
|
|
}, function(err, data) {
|
|
|
|
|
|
|
|
callback(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
lwip.open(path, function(err, image) {
|
|
|
|
lwip.open(path, function(err, image) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
image.writeFile(path, 'png', callback)
|
|
|
|
image.writeFile(path, 'png', callback)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|