mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
closes #1130
This commit is contained in:
36
src/image.js
36
src/image.js
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs'),
|
||||
imagemagick = require('node-imagemagick'),
|
||||
gm = require('gm').subClass({imageMagick: true}),
|
||||
meta = require('./meta');
|
||||
|
||||
var image = {};
|
||||
@@ -11,35 +12,26 @@ image.resizeImage = function(path, extension, width, height, callback) {
|
||||
}
|
||||
|
||||
if(extension === '.gif') {
|
||||
imagemagick.convert([
|
||||
path,
|
||||
'-coalesce',
|
||||
'-repage',
|
||||
'0x0',
|
||||
'-crop',
|
||||
width+'x'+height+'+0+0',
|
||||
'+repage',
|
||||
path
|
||||
], done);
|
||||
gm().in(path)
|
||||
.in('-coalesce')
|
||||
.in('-resize')
|
||||
.in(width+'x'+height)
|
||||
.write(path, done);
|
||||
} else {
|
||||
imagemagick.crop({
|
||||
srcPath: path,
|
||||
dstPath: path,
|
||||
width: width,
|
||||
height: height
|
||||
}, done);
|
||||
gm(path)
|
||||
.crop(width, height, 0, 0)
|
||||
.write(path, done);
|
||||
}
|
||||
};
|
||||
|
||||
image.convertImageToPng = function(path, extension, callback) {
|
||||
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
||||
if(convertToPNG && extension !== '.png') {
|
||||
imagemagick.convert([path, 'png:-'], function(err, stdout) {
|
||||
if(err) {
|
||||
gm(path).toBuffer('png', function(err, buffer) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
fs.writeFile(path, stdout, 'binary', callback);
|
||||
fs.writeFile(path, buffer, 'binary', callback);
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
@@ -50,6 +42,6 @@ image.convertImageToBase64 = function(path, callback) {
|
||||
fs.readFile(path, function(err, data) {
|
||||
callback(err, data ? data.toString('base64') : null);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = image;
|
||||
Reference in New Issue
Block a user