mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
closes #4590
This commit is contained in:
@@ -71,8 +71,25 @@ uploadsController.uploadPost = function(req, res, next) {
|
||||
return next(null, fileObj);
|
||||
}
|
||||
|
||||
var fullPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), '..', fileObj.url);
|
||||
//var parsedPath = path.parse(fullPath);
|
||||
resizeImage(fileObj, next);
|
||||
}
|
||||
], next);
|
||||
}, next);
|
||||
};
|
||||
|
||||
function resizeImage(fileObj, callback) {
|
||||
var fullPath;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
fullPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), '..', fileObj.url);
|
||||
|
||||
image.load(fullPath, next);
|
||||
},
|
||||
function (imageData, next) {
|
||||
if (imageData.width < parseInt(meta.config.maximumImageWidth, 10) || 760) {
|
||||
return callback(null, fileObj);
|
||||
}
|
||||
|
||||
var dirname = path.dirname(fullPath);
|
||||
var extname = path.extname(fullPath);
|
||||
var basename = path.basename(fullPath, extname);
|
||||
@@ -82,11 +99,9 @@ uploadsController.uploadPost = function(req, res, next) {
|
||||
target: path.join(dirname, basename + '-resized' + extname),
|
||||
extension: extname,
|
||||
width: parseInt(meta.config.maximumImageWidth, 10) || 760
|
||||
}, function(err) {
|
||||
next(err, fileObj);
|
||||
});
|
||||
}, next);
|
||||
},
|
||||
function (fileObj, next) {
|
||||
function (next) {
|
||||
|
||||
// Return the resized version to the composer/postData
|
||||
var dirname = path.dirname(fileObj.url);
|
||||
@@ -97,9 +112,8 @@ uploadsController.uploadPost = function(req, res, next) {
|
||||
|
||||
next(null, fileObj);
|
||||
}
|
||||
], next);
|
||||
}, next);
|
||||
};
|
||||
], callback);
|
||||
}
|
||||
|
||||
uploadsController.uploadThumb = function(req, res, next) {
|
||||
if (parseInt(meta.config.allowTopicsThumbnail, 10) !== 1) {
|
||||
|
||||
10
src/image.js
10
src/image.js
@@ -15,7 +15,7 @@ image.resizeImage = function(data, callback) {
|
||||
extension: data.extension,
|
||||
width: data.width,
|
||||
height: data.height
|
||||
}, function(err, data) {
|
||||
}, function(err) {
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
@@ -79,7 +79,7 @@ image.normalise = function(path, extension, callback) {
|
||||
plugins.fireHook('filter:image.normalise', {
|
||||
path: path,
|
||||
extension: extension
|
||||
}, function(err, data) {
|
||||
}, function(err) {
|
||||
callback(err);
|
||||
});
|
||||
} else {
|
||||
@@ -94,6 +94,12 @@ image.normalise = function(path, extension, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
image.load = function(path, callback) {
|
||||
new Jimp(path, function(err, data) {
|
||||
callback(err, data ? data.bitmap : null);
|
||||
});
|
||||
};
|
||||
|
||||
image.convertImageToBase64 = function(path, callback) {
|
||||
fs.readFile(path, function(err, data) {
|
||||
callback(err, data ? data.toString('base64') : null);
|
||||
|
||||
Reference in New Issue
Block a user