added plugin hooks so that imagemagick can still be called, as a plugin, for image manipulation tasks, falling back to using lwip

v1.18.x
Julian Lam 10 years ago
parent 88dd8b1d4d
commit e523ef7c17

@ -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();
} }
}; };

@ -41,7 +41,7 @@ module.exports = function(User) {
}, },
function(next) { function(next) {
if (convertToPNG) { if (convertToPNG) {
image.convertImageToPng(picture.path, extension, next); image.normalise(picture.path, extension, next);
} else { } else {
next(); next();
} }

Loading…
Cancel
Save