Switched to using Sharp to fix JPEG uploads failing (remove Jimp)

pull/125/head
tycrek 2 years ago
parent c1a5d77f0f
commit b44172d999
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

1525
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -58,7 +58,6 @@
"ffmpeg-static": "^4.4.0",
"fs-extra": "^10.0.0",
"helmet": "^4.6.0",
"jimp": "^0.16.1",
"luxon": "^2.0.2",
"node-fetch": "^2.6.7",
"node-vibrant": "^3.1.6",
@ -66,6 +65,7 @@
"prompt": "^1.2.0",
"pug": "^3.0.2",
"sanitize-filename": "^1.6.3",
"sharp": "^0.30.3",
"stream-to-array": "^2.3.0",
"submodule": "^1.2.1",
"tailwindcss": "^3.0.23",
@ -82,6 +82,7 @@
"@types/marked": "^3.0.0",
"@types/node": "^16.9.0",
"@types/node-fetch": "^2.5.12",
"@types/sharp": "^0.30.2",
"@types/stream-to-array": "^2.3.0",
"@types/tailwindcss": "^3.0.9",
"@types/uuid": "^8.3.1",

@ -2,7 +2,8 @@ import { FileData } from './types/definitions';
import { Config } from 'ass-json';
import fs from 'fs-extra';
import ffmpeg from 'ffmpeg-static';
import Jimp from 'jimp';
import sharp from 'sharp';
// @ts-ignore
import shell from 'any-shell-escape';
import { exec } from 'child_process';
@ -70,11 +71,10 @@ function getVideoThumbnail(file: FileData) {
*/
function getImageThumbnail(file: FileData) {
return new Promise((resolve, reject) =>
Jimp.read(file.path)
.then((image) => image
.quality(THUMBNAIL.QUALITY)
.resize(THUMBNAIL.WIDTH, THUMBNAIL.HEIGHT, Jimp.RESIZE_BICUBIC)
.write(getNewNamePath(file.randomId)))
sharp(file.path)
.resize(THUMBNAIL.WIDTH, THUMBNAIL.HEIGHT, { kernel: 'cubic' })
.jpeg({ quality: THUMBNAIL.QUALITY })
.toFile(getNewNamePath(file.randomId))
.then(resolve)
.catch(reject));
}

@ -1,5 +1,6 @@
import { FileData } from './types/definitions';
import Vibrant from 'node-vibrant';
import sharp from 'sharp';
import { randomHexColour } from './utils';
// Vibrant parameters
@ -13,10 +14,11 @@ const QUALITY = 3;
* @param {*} reject Runs if Promise failed
*/
function getVibrant(file: FileData, resolve: Function, reject: Function) {
Vibrant.from(file.path)
.maxColorCount(COLOR_COUNT)
.quality(QUALITY)
.getPalette()
sharp(file.path).png().toBuffer()
.then((data) => Vibrant.from(data)
.maxColorCount(COLOR_COUNT)
.quality(QUALITY)
.getPalette())
.then((palettes) => resolve(palettes[Object.keys(palettes).sort((a, b) => palettes[b]!.population - palettes[a]!.population)[0]]!.hex))
.catch((err) => reject(err));
}

Loading…
Cancel
Save