Skip to content

Node.js based forum software built for the modern web

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

Julian Lame523ef7c17d2
diff --git a/src/image.js b/src/image.js
index 2fc391ed20..078b2d134d 100644
--- a/src/image.js
+++ b/src/image.js
@@ -1,31 +1,48 @@
'use strict';
var fs = require('fs'),
- lwip = require('lwip');
+ lwip = require('lwip'),
+ plugins = require('./plugins');
var image = {};
image.resizeImage = function(path, extension, width, height, callback) {
- lwip.open(path, function(err, image) {
- image.batch()
- .cover(width, height)
- .crop(width, height)
- .writeFile(path, function(err) {
- callback(err)
- })
+ 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) {
+ image.batch()
+ .cover(width, height)
+ .crop(width, height)
+ .writeFile(path, function(err) {
+ callback(err)
+ })
+ });
+ }
};
-image.convertImageToPng = function(path, extension, callback) {
- if(extension !== '.png') {
+image.normalise = function(path, extension, callback) {
+ 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) {
if (err) {
return callback(err);
}
image.writeFile(path, 'png', callback)
});
- } else {
- callback();
}
};
diff --git a/src/user/picture.js b/src/user/picture.js
index 8f030091a9..ada87589d6 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -41,7 +41,7 @@ module.exports = function(User) {
},
function(next) {
if (convertToPNG) {
- image.convertImageToPng(picture.path, extension, next);
+ image.normalise(picture.path, extension, next);
} else {
next();
}