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:
Barış Soner Uşaklı
2018-09-20 17:05:52 -04:00
committed by GitHub
parent 69c7260fe9
commit b7ead6dc9c
16 changed files with 140 additions and 126 deletions

View File

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