This commit is contained in:
barisusakli
2016-05-01 12:44:43 +03:00
parent e9d548d057
commit fea18a050f
2 changed files with 47 additions and 27 deletions

View File

@@ -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) {

View File

@@ -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);