mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
Swap out ImageMagick for lwip
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
"daemon": "~1.1.0",
|
"daemon": "~1.1.0",
|
||||||
"express": "^4.9.5",
|
"express": "^4.9.5",
|
||||||
"express-session": "^1.8.2",
|
"express-session": "^1.8.2",
|
||||||
"gm": "1.17.0",
|
"lwip": "0.0.6",
|
||||||
"gravatar": "^1.1.0",
|
"gravatar": "^1.1.0",
|
||||||
"heapdump": "^0.3.0",
|
"heapdump": "^0.3.0",
|
||||||
"less": "^2.0.0",
|
"less": "^2.0.0",
|
||||||
|
|||||||
30
src/image.js
30
src/image.js
@@ -1,38 +1,28 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
gm = require('gm').subClass({imageMagick: true});
|
lwip = require('lwip');
|
||||||
|
|
||||||
var image = {};
|
var image = {};
|
||||||
|
|
||||||
image.resizeImage = function(path, extension, width, height, callback) {
|
image.resizeImage = function(path, extension, width, height, callback) {
|
||||||
function done(err, stdout, stderr) {
|
lwip.open(path, function(err, image) {
|
||||||
callback(err);
|
image.batch()
|
||||||
}
|
.cover(width, height)
|
||||||
|
|
||||||
if(extension === '.gif') {
|
|
||||||
gm().in(path)
|
|
||||||
.in('-coalesce')
|
|
||||||
.in('-resize')
|
|
||||||
.in(width+'x'+height+'^')
|
|
||||||
.write(path, done);
|
|
||||||
} else {
|
|
||||||
gm(path)
|
|
||||||
.in('-resize')
|
|
||||||
.in(width+'x'+height+'^')
|
|
||||||
.gravity('Center')
|
|
||||||
.crop(width, height)
|
.crop(width, height)
|
||||||
.write(path, done);
|
.writeFile(path, function(err) {
|
||||||
}
|
callback(err)
|
||||||
|
})
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
image.convertImageToPng = function(path, extension, callback) {
|
image.convertImageToPng = function(path, extension, callback) {
|
||||||
if(extension !== '.png') {
|
if(extension !== '.png') {
|
||||||
gm(path).toBuffer('png', function(err, buffer) {
|
lwip.open(path, function(err, image) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
fs.writeFile(path, buffer, 'binary', callback);
|
image.writeFile(path, 'png', callback)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user