mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-04 21:15:55 +01:00
convert profile images to static png if setting is checked in control panel, closes #562
This commit is contained in:
@@ -102,7 +102,7 @@ var fs = require('fs'),
|
||||
if (!req.user)
|
||||
return res.redirect('/403');
|
||||
|
||||
var uploadSize = meta.config.maximumProfileImageSize || 256;
|
||||
var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
|
||||
|
||||
if (req.files.userPhoto.size > uploadSize * 1024) {
|
||||
res.send({
|
||||
@@ -147,18 +147,21 @@ var fs = require('fs'),
|
||||
return;
|
||||
}
|
||||
|
||||
var filename = uid + '-profileimg' + extension;
|
||||
var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10);
|
||||
|
||||
var filename = uid + '-profileimg' + (convertToPNG ? '.png' : extension);
|
||||
var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), filename);
|
||||
|
||||
winston.info('Attempting upload to: ' + uploadPath);
|
||||
|
||||
var is = fs.createReadStream(tempPath);
|
||||
var os = fs.createWriteStream(uploadPath);
|
||||
var im = require('node-imagemagick');
|
||||
|
||||
is.on('end', function () {
|
||||
fs.unlinkSync(tempPath);
|
||||
|
||||
require('node-imagemagick').crop({
|
||||
im.crop({
|
||||
srcPath: uploadPath,
|
||||
dstPath: uploadPath,
|
||||
width: 128,
|
||||
@@ -177,6 +180,22 @@ var fs = require('fs'),
|
||||
user.setUserField(uid, 'uploadedpicture', imageUrl);
|
||||
user.setUserField(uid, 'picture', imageUrl);
|
||||
|
||||
if (convertToPNG) {
|
||||
im.convert([uploadPath, 'png:-'],
|
||||
function(err, stdout){
|
||||
if (err) {
|
||||
winston.err(err);
|
||||
res.send({
|
||||
error: 'Unable to convert image to PNG.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFileSync(uploadPath, stdout, 'binary');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
res.json({
|
||||
path: imageUrl
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user