Skip to content

Commit

Permalink
Replaces Jimp by Sharp. Needs lots of testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
digimezzo committed Feb 27, 2024
1 parent e4adf15 commit e75852f
Show file tree
Hide file tree
Showing 6 changed files with 374 additions and 14 deletions.
1 change: 1 addition & 0 deletions main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as os from 'os';
import * as path from 'path';
import * as url from 'url';
import { Worker } from 'worker_threads';
const sharp = require('sharp'); // required to use sharp in worker threads

/**
* Command line parameters
Expand Down
15 changes: 7 additions & 8 deletions main/common/image-processor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs-extra');
const Jimp = require('jimp');
const sharp = require('sharp');

class ImageProcessor {
constructor(fileAccess) {
Expand All @@ -16,13 +16,12 @@ class ImageProcessor {
}

async resizeAndWriteImageAsync(imageBuffer, imagePath, maxWidth, maxHeight, jpegQuality) {
let image = await Jimp.read(imageBuffer);

if (image.bitmap.width > maxWidth || image.bitmap.height > maxHeight) {
await image.resize(maxWidth, maxHeight);
}

await image.quality(jpegQuality).writeAsync(imagePath);
sharp(imageBuffer)
.resize(maxWidth, maxHeight)
.jpeg({
quality: jpegQuality,
})
.toFile(imagePath, (err, info) => {});
}
}

Expand Down
Loading

0 comments on commit e75852f

Please sign in to comment.