diff --git a/docs/api-input.md b/docs/api-input.md index 9c1167a3..0e6a4947 100644 --- a/docs/api-input.md +++ b/docs/api-input.md @@ -22,6 +22,7 @@ A `Promise` is returned when `callback` is not provided. * `pagePrimary`: Number of the primary page in a HEIF image * `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide * `subifds`: Number of Sub Image File Directories in an OME-TIFF image +* `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) * `hasProfile`: Boolean indicating the presence of an embedded ICC profile * `hasAlpha`: Boolean indicating the presence of an alpha transparency channel * `orientation`: Number value of the EXIF Orientation header, if present diff --git a/docs/changelog.md b/docs/changelog.md index bdfe1478..ee590bfe 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,9 @@ Requires libvips v8.11.0 * Drop support for Node.js 10, now requires Node.js >= 12.13.0. +* Add `compression` property to HEIF image metadata. + [#2504](https://github.com/lovell/sharp/issues/2504) + * AVIF encoding now defaults to `4:4:4` chroma subsampling. [#2562](https://github.com/lovell/sharp/issues/2562) diff --git a/lib/input.js b/lib/input.js index 4c28d6a2..38f6105d 100644 --- a/lib/input.js +++ b/lib/input.js @@ -271,6 +271,7 @@ function _isStreamInput () { * - `pagePrimary`: Number of the primary page in a HEIF image * - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide * - `subifds`: Number of Sub Image File Directories in an OME-TIFF image + * - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) * - `hasProfile`: Boolean indicating the presence of an embedded ICC profile * - `hasAlpha`: Boolean indicating the presence of an alpha transparency channel * - `orientation`: Number value of the EXIF Orientation header, if present diff --git a/test/unit/metadata.js b/test/unit/metadata.js index c5699b03..1aa2f343 100644 --- a/test/unit/metadata.js +++ b/test/unit/metadata.js @@ -724,6 +724,25 @@ describe('Image metadata', function () { }) ); + it('AVIF', async () => { + const metadata = await sharp(fixtures.inputAvif).metadata(); + assert.deepStrictEqual(metadata, { + format: 'heif', + width: 2048, + height: 858, + space: 'srgb', + channels: 3, + depth: 'uchar', + isProgressive: false, + pages: 1, + pageHeight: 858, + pagePrimary: 0, + compression: 'av1', + hasProfile: false, + hasAlpha: false + }); + }); + it('File input with corrupt header fails gracefully', function (done) { sharp(fixtures.inputJpgWithCorruptHeader) .metadata(function (err) {