Add AVIF/HEIF 'tune' option to control quality metrics #4227

This commit is contained in:
Lovell Fuller
2026-01-01 22:41:18 +00:00
parent 0d872bd13a
commit 006d37b2d0
10 changed files with 53 additions and 2 deletions

View File

@@ -181,4 +181,16 @@ describe('AVIF', () => {
/Expected 8, 10 or 12 for bitdepth but received 11 of type number/
)
);
it('Different tune options result in different file sizes', async () => {
const ssim = await sharp(inputJpg)
.resize(32)
.avif({ tune: 'ssim', effort: 0 })
.toBuffer();
const iq = await sharp(inputJpg)
.resize(32)
.avif({ tune: 'iq', effort: 0 })
.toBuffer();
assert(ssim.length < iq.length);
})
});

View File

@@ -96,4 +96,14 @@ describe('HEIF', () => {
sharp().heif({ compression: 'av1', bitdepth: 11 });
}, /Error: Expected 8, 10 or 12 for bitdepth but received 11 of type number/);
});
it('valid tune does not throw an error', () => {
assert.doesNotThrow(() => {
sharp().heif({ compression: 'hevc', tune: 'psnr' });
});
});
it('invalid tune should throw an error', () => {
assert.throws(() => {
sharp().heif({ compression: 'hevc', tune: 'fail' });
}, /Error: Expected one of: psnr, ssim, iq for tune but received fail of type string/);
});
});