mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-27 00:55:33 +02:00
Replace jimp with sharp (#6774)
* add probe image size and max image size * replace jimp and image-probe with sharp * better name for test * resize with just path * resize thumb inplace * use filename
This commit is contained in:
committed by
GitHub
parent
69c7260fe9
commit
b7ead6dc9c
@@ -5,7 +5,6 @@ var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
var mime = require('mime');
|
||||
var fs = require('fs');
|
||||
var jimp = require('jimp');
|
||||
|
||||
var meta = require('../../meta');
|
||||
var posts = require('../../posts');
|
||||
@@ -177,16 +176,13 @@ uploadsController.uploadTouchIcon = function (req, res, next) {
|
||||
}
|
||||
|
||||
// Resize the image into squares for use as touch icons at various DPIs
|
||||
async.each(sizes, function (size, next) {
|
||||
async.series([
|
||||
async.apply(file.saveFileToLocal, 'touchicon-' + size + '.png', 'system', uploadedFile.path),
|
||||
async.apply(image.resizeImage, {
|
||||
path: path.join(nconf.get('upload_path'), 'system', 'touchicon-' + size + '.png'),
|
||||
extension: 'png',
|
||||
width: size,
|
||||
height: size,
|
||||
}),
|
||||
], next);
|
||||
async.eachSeries(sizes, function (size, next) {
|
||||
image.resizeImage({
|
||||
path: uploadedFile.path,
|
||||
target: path.join(nconf.get('upload_path'), 'system', 'touchicon-' + size + '.png'),
|
||||
width: size,
|
||||
height: size,
|
||||
}, next);
|
||||
}, function (err) {
|
||||
file.delete(uploadedFile.path);
|
||||
|
||||
@@ -291,7 +287,6 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
||||
async.apply(image.resizeImage, {
|
||||
path: uploadedFile.path,
|
||||
target: uploadPath,
|
||||
extension: 'png',
|
||||
height: 50,
|
||||
}),
|
||||
async.apply(meta.configs.set, 'brand:emailLogo', path.join(nconf.get('upload_url'), 'system/site-logo-x50.png')),
|
||||
@@ -299,15 +294,16 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) {
|
||||
next(err, imageData);
|
||||
});
|
||||
} else if (path.basename(filename, path.extname(filename)) === 'og:image' && folder === 'system') {
|
||||
jimp.read(imageData.path).then(function (image) {
|
||||
image.size(imageData.path, function (err, size) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
meta.configs.setMultiple({
|
||||
'og:image:height': image.bitmap.height,
|
||||
'og:image:width': image.bitmap.width,
|
||||
'og:image:width': size.width,
|
||||
'og:image:height': size.height,
|
||||
}, function (err) {
|
||||
next(err, imageData);
|
||||
});
|
||||
}).catch(function (err) {
|
||||
next(err);
|
||||
});
|
||||
} else {
|
||||
setImmediate(next, null, imageData);
|
||||
|
||||
@@ -25,7 +25,7 @@ uploadsController.upload = function (req, res, filesIterator) {
|
||||
files = files[0];
|
||||
}
|
||||
|
||||
async.map(files, filesIterator, function (err, images) {
|
||||
async.mapSeries(files, filesIterator, function (err, images) {
|
||||
deleteTempFiles(files);
|
||||
|
||||
if (err) {
|
||||
@@ -56,6 +56,9 @@ function uploadAsImage(req, uploadedFile, callback) {
|
||||
if (!canUpload) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
image.checkDimensions(uploadedFile.path, next);
|
||||
},
|
||||
function (next) {
|
||||
if (plugins.hasListeners('filter:uploadImage')) {
|
||||
return plugins.fireHook('filter:uploadImage', {
|
||||
image: uploadedFile,
|
||||
@@ -113,14 +116,9 @@ function resizeImage(fileObj, callback) {
|
||||
return callback(null, fileObj);
|
||||
}
|
||||
|
||||
var dirname = path.dirname(fileObj.path);
|
||||
var extname = path.extname(fileObj.path);
|
||||
var basename = path.basename(fileObj.path, extname);
|
||||
|
||||
image.resizeImage({
|
||||
path: fileObj.path,
|
||||
target: path.join(dirname, basename + '-resized' + extname),
|
||||
extension: extname,
|
||||
target: file.appendToFileName(fileObj.path, '-resized'),
|
||||
width: parseInt(meta.config.maximumImageWidth, 10) || 760,
|
||||
quality: parseInt(meta.config.resizeImageQuality, 10) || 60,
|
||||
}, next);
|
||||
@@ -157,7 +155,6 @@ uploadsController.uploadThumb = function (req, res, next) {
|
||||
var size = parseInt(meta.config.topicThumbSize, 10) || 120;
|
||||
image.resizeImage({
|
||||
path: uploadedFile.path,
|
||||
extension: path.extname(uploadedFile.name),
|
||||
width: size,
|
||||
height: size,
|
||||
}, next);
|
||||
|
||||
Reference in New Issue
Block a user