Standardise HEIF effort option name, deprecate speed

This commit is contained in:
Lovell Fuller
2021-11-24 19:54:04 +00:00
parent 2b1f5cbe07
commit e1ba2a7fd8
8 changed files with 50 additions and 29 deletions

View File

@@ -17,10 +17,9 @@ describe('AVIF', () => {
.resize(32)
.jpeg()
.toBuffer();
const metadata = await sharp(data)
const { size, ...metadata } = await sharp(data)
.metadata();
const { compression, size, ...metadataWithoutSize } = metadata;
assert.deepStrictEqual(metadataWithoutSize, {
assert.deepStrictEqual(metadata, {
channels: 3,
chromaSubsampling: '4:2:0',
density: 72,
@@ -38,13 +37,13 @@ describe('AVIF', () => {
it('can convert JPEG to AVIF', async () => {
const data = await sharp(inputJpg)
.resize(32)
.avif()
.avif({ effort: 0 })
.toBuffer();
const metadata = await sharp(data)
const { size, ...metadata } = await sharp(data)
.metadata();
const { compression, size, ...metadataWithoutSize } = metadata;
assert.deepStrictEqual(metadataWithoutSize, {
assert.deepStrictEqual(metadata, {
channels: 3,
compression: 'av1',
depth: 'uchar',
format: 'heif',
hasAlpha: false,
@@ -63,11 +62,11 @@ describe('AVIF', () => {
const data = await sharp(inputAvif)
.resize(32)
.toBuffer();
const metadata = await sharp(data)
const { size, ...metadata } = await sharp(data)
.metadata();
const { compression, size, ...metadataWithoutSize } = metadata;
assert.deepStrictEqual(metadataWithoutSize, {
assert.deepStrictEqual(metadata, {
channels: 3,
compression: 'av1',
depth: 'uchar',
format: 'heif',
hasAlpha: false,
@@ -85,12 +84,11 @@ describe('AVIF', () => {
it('can convert animated GIF to non-animated AVIF', async () => {
const data = await sharp(inputGifAnimated, { animated: true })
.resize(10)
.avif({ speed: 8 })
.avif({ effort: 0 })
.toBuffer();
const metadata = await sharp(data)
const { size, ...metadata } = await sharp(data)
.metadata();
const { size, ...metadataWithoutSize } = metadata;
assert.deepStrictEqual(metadataWithoutSize, {
assert.deepStrictEqual(metadata, {
channels: 4,
compression: 'av1',
depth: 'uchar',

View File

@@ -50,6 +50,21 @@ describe('HEIF', () => {
sharp().heif({ compression: 1 });
});
});
it('valid effort does not throw an error', () => {
assert.doesNotThrow(() => {
sharp().heif({ speed: 6 });
});
});
it('out of range effort should throw an error', () => {
assert.throws(() => {
sharp().heif({ effort: 10 });
});
});
it('invalid effort should throw an error', () => {
assert.throws(() => {
sharp().heif({ effort: 'fail' });
});
});
it('valid speed does not throw an error', () => {
assert.doesNotThrow(() => {
sharp().heif({ speed: 6 });
@@ -62,7 +77,7 @@ describe('HEIF', () => {
});
it('invalid speed should throw an error', () => {
assert.throws(() => {
sharp().heif({ compression: 'fail' });
sharp().heif({ speed: 'fail' });
});
});
it('invalid chromaSubsampling should throw an error', () => {