Skip to content

Commit

Permalink
Use HERMITE instead of default resize.
Browse files Browse the repository at this point in the history
Default jimp resize didn't handle large values (2000) when running
in Docker AMD on a a ARM so changing to another algorithm.

sitespeedio/sitespeed.io#3922
  • Loading branch information
soulgalore committed Jul 31, 2023
1 parent e3b05f0 commit 18bdf7f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/support/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ export async function savePng(
}

if (jimp) {
const buffer = await jimp.default.read(data).then(image => {
return image
.deflateLevel(config.png.compressionLevel)
.scaleToFit(config.maxSize, config.maxSize)
.getBufferAsync('image/png');
});
const image = await jimp.default.read(data);
const buffer = await image
.deflateLevel(config.png.compressionLevel)
.scaleToFit(config.maxSize, config.maxSize, jimp.default.RESIZE_HERMITE)
.getBufferAsync('image/png');

return storageManager.writeData(
`${name}.png`,
Expand All @@ -62,12 +61,12 @@ export async function saveJpg(
jimp = undefined;
}
if (jimp) {
const buffer = await jimp.default.read(data).then(image => {
return image
.quality(config.jpg.quality)
.scaleToFit(config.maxSize, config.maxSize)
.getBufferAsync('image/jpeg');
});
const image = await jimp.default.read(data);
// https://github.com/sitespeedio/sitespeed.io/issues/3922
const buffer = await image
.quality(config.jpg.quality)
.scaleToFit(config.maxSize, config.maxSize, jimp.default.RESIZE_HERMITE)
.getBufferAsync('image/jpeg');
return storageManager.writeData(
`${name}.jpg`,
buffer,
Expand Down

0 comments on commit 18bdf7f

Please sign in to comment.