Encoding lossless AVIF is mutually exclusive with iq tuning

This commit is contained in:
Lovell Fuller
2026-01-07 20:39:53 +00:00
parent 4b1680c312
commit 0468c1be9f
3 changed files with 37 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ const { describe, it } = require('node:test');
const assert = require('node:assert');
const sharp = require('../../');
const { inputAvif, inputJpg, inputGifAnimated } = require('../fixtures');
const { inputAvif, inputJpg, inputGifAnimated, inputPng } = require('../fixtures');
describe('AVIF', () => {
it('called without options does not throw an error', () => {
@@ -74,6 +74,35 @@ describe('AVIF', () => {
});
});
it('can convert PNG to lossless AVIF', async () => {
const data = await sharp(inputPng)
.resize(32)
.avif({ lossless: true, effort: 0 })
.toBuffer();
const { size, ...metadata } = await sharp(data).metadata();
void size;
assert.deepStrictEqual(metadata, {
autoOrient: {
height: 24,
width: 32
},
channels: 3,
compression: 'av1',
depth: 'uchar',
format: 'heif',
hasAlpha: false,
hasProfile: false,
height: 24,
isProgressive: false,
isPalette: false,
bitsPerSample: 8,
pagePrimary: 0,
pages: 1,
space: 'srgb',
width: 32
});
});
it('can passthrough AVIF', async () => {
const data = await sharp(inputAvif)
.resize(32)