mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +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:
41
src/image.js
41
src/image.js
@@ -1,31 +1,48 @@
|
|||||||
'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) {
|
||||||
lwip.open(path, function(err, image) {
|
if (plugins.hasListeners('filter:image.resize')) {
|
||||||
image.batch()
|
plugins.fireHook('filter:image.resize', {
|
||||||
.cover(width, height)
|
path: path,
|
||||||
.crop(width, height)
|
extension: extension,
|
||||||
.writeFile(path, function(err) {
|
width: width,
|
||||||
callback(err)
|
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) {
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user