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

@@ -2,7 +2,6 @@
var async = require('async');
var path = require('path');
var Jimp = require('jimp');
var mime = require('mime');
var db = require('../database');
@@ -27,7 +26,6 @@ module.exports = function (Groups) {
var tempPath = data.file ? data.file : '';
var url;
var type = data.file ? mime.getType(data.file) : 'image/png';
async.waterfall([
function (next) {
if (tempPath) {
@@ -49,7 +47,10 @@ module.exports = function (Groups) {
Groups.setGroupField(data.groupName, 'cover:url', url, next);
},
function (next) {
resizeCover(tempPath, next);
image.resizeImage({
path: tempPath,
width: 358,
}, next);
},
function (next) {
uploadsController.uploadGroupCover(uid, {
@@ -74,22 +75,6 @@ module.exports = function (Groups) {
});
};
function resizeCover(path, callback) {
async.waterfall([
function (next) {
new Jimp(path, next);
},
function (image, next) {
image.resize(358, Jimp.AUTO, next);
},
function (image, next) {
image.write(path, next);
},
], function (err) {
callback(err);
});
}
Groups.removeCover = function (data, callback) {
db.deleteObjectFields('group:' + data.groupName, ['cover:url', 'cover:thumb:url', 'cover:position'], callback);
};