mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 05:36:18 +01:00
Add AVIF/HEIF 'tune' option to control quality metrics #4227
This commit is contained in:
@@ -365,7 +365,7 @@ sharp(input)
|
||||
.avif({ quality: 50, lossless: false, effort: 5, chromaSubsampling: '4:2:0' })
|
||||
.heif()
|
||||
.heif({})
|
||||
.heif({ quality: 50, compression: 'hevc', lossless: false, effort: 5, chromaSubsampling: '4:2:0' })
|
||||
.heif({ quality: 50, compression: 'hevc', lossless: false, effort: 5, chromaSubsampling: '4:2:0', tune: 'psnr' })
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(({ data, info }) => {
|
||||
console.log(data);
|
||||
|
||||
@@ -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);
|
||||
})
|
||||
});
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user