From e523ef7c17d25d7aae582679091f3a3129e77adf Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 4 Jun 2015 12:32:39 -0400 Subject: [PATCH] added plugin hooks so that imagemagick can still be called, as a plugin, for image manipulation tasks, falling back to using lwip --- src/image.js | 41 +++++++++++++++++++++++++++++------------ src/user/picture.js | 2 +- 2 files changed, 30 insertions(+), 13 deletions(-) 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(); }