mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
added plugin hooks so that imagemagick can still be called, as a plugin, for image manipulation tasks, falling back to using lwip
This commit is contained in:
27
src/image.js
27
src/image.js
@@ -1,11 +1,22 @@
|
||||
'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) {
|
||||
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)
|
||||
@@ -14,18 +25,24 @@ image.resizeImage = function(path, extension, width, height, callback) {
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user