1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

Replace sharp with jimp for image processing

This commit is contained in:
Andrew Kingston 2020-10-21 13:00:23 +01:00
parent 5c3d7481f6
commit 64812e2ddc
3 changed files with 689 additions and 262 deletions

View file

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

View file

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

File diff suppressed because it is too large Load diff