Replace sharp with jimp for image processing

This commit is contained in:
Andrew Kingston 2020-10-21 13:00:23 +01:00
parent 2bfb72da2b
commit 8428bebc13
3 changed files with 689 additions and 262 deletions

View File

@ -57,6 +57,7 @@
"electron-updater": "^4.3.1", "electron-updater": "^4.3.1",
"fix-path": "^3.0.0", "fix-path": "^3.0.0",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"jimp": "^0.16.1",
"joi": "^17.2.1", "joi": "^17.2.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"koa": "^2.7.0", "koa": "^2.7.0",
@ -73,7 +74,6 @@
"pouchdb": "^7.2.1", "pouchdb": "^7.2.1",
"pouchdb-all-dbs": "^1.0.2", "pouchdb-all-dbs": "^1.0.2",
"pouchdb-replication-stream": "^1.2.9", "pouchdb-replication-stream": "^1.2.9",
"sharp": "^0.26.0",
"squirrelly": "^7.5.0", "squirrelly": "^7.5.0",
"tar-fs": "^2.1.0", "tar-fs": "^2.1.0",
"uuid": "^3.3.2", "uuid": "^3.3.2",

View File

@ -1,24 +1,21 @@
const fs = require("fs") const fs = require("fs")
const sharp = require("sharp") const jimp = require("jimp")
const fsPromises = fs.promises const fsPromises = fs.promises
const FORMATS = { const FORMATS = {
IMAGES: ["png", "jpg", "jpeg", "gif", "svg", "tiff", "raw"], IMAGES: ["png", "jpg", "jpeg", "gif", "bmp", "tiff"],
} }
async function processImage(file) { function processImage(file) {
const imgMeta = await sharp(file.path) return jimp.read(file.path).then(img => {
.resize(300) return img.resize(300, jimp.AUTO).write(file.outputPath)
.toFile(file.outputPath) })
return {
...file,
...imgMeta,
}
} }
async function process(file) { async function process(file) {
if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) { if (FORMATS.IMAGES.includes(file.extension.toLowerCase())) {
return await processImage(file) await processImage(file)
return file
} }
// No processing required // No processing required

File diff suppressed because it is too large Load Diff