Skip to content

Error using keepGainMap() + keepMetadata() #4517

Closed

Description

@gregbenz

@lovell Great to see keepGainMap() support added!

I'm doing some testing with 0.35.0-rc.2 and see a potential bug:

Summary

On my local setup, keepGainMap() and keepMetadata() each work on their own, but chaining them as:

sharp(input).keepGainMap().keepMetadata().jpeg({ quality: 90 })

fails for gain-map JPEG input with:

vips_image_get: field "gainmap-max-content-boost" not found

This appears to be specific to the keepGainMap() + keepMetadata() combination on gain-map JPEGs, not a general keepMetadata() failure.

Environment

source images:
sample gain maps.zip

  • Node.js v20.12.2
  • sharp 0.35.0-rc.2
  • libvips 8.18.2

Example

import sharp from "sharp";

const input = "myGainMap.jpg";

await sharp(input)
  .keepGainMap()
  .keepMetadata()
  .jpeg({ quality: 90 })
  .toBuffer();

Actual result

Error: vips_image_get: field "gainmap-max-content-boost" not found

Expected result

The transcode should succeed and preserve both:

  • the gain map via keepGainMap()
  • metadata via keepMetadata()

Control cases

These all succeeded locally with the same input:

await sharp(input)
  .keepMetadata()
  .jpeg({ quality: 90 })
  .toBuffer();

await sharp(input)
  .keepGainMap()
  .jpeg({ quality: 90 })
  .toBuffer();

await sharp(input)
  .withGainMap()
  .keepMetadata()
  .jpeg({ quality: 90 })
  .toBuffer();

await sharp(input)
  .keepGainMap()
  .keepExif()
  .keepIccProfile()
  .keepXmp()
  .jpeg({ quality: 90 })
  .toBuffer();

This also succeeded, which suggests the issue may be ordering-related:

await sharp(input)
  .keepMetadata()
  .keepGainMap()
  .jpeg({ quality: 90 })
  .toBuffer();

Activity

  1. added and removed on Apr 10, 2026
  2. lovell commented on Apr 10, 2026

    @lovell
    Owner

    Thanks for testing and reporting this Greg, luckily it was a small thing I'd overlooked. I've added your sample code as a test case to help prevent regression - see commit ce4a669

    I'll close this issue as HDR support is still pre-release.

  3. gregbenz commented on Apr 10, 2026

    @gregbenz
    Author

    @lovell Great, thanks!

    One minor comment just to capture it... in my testing, an image with an Android XMP map only (which is supported by libultrahdr) was not detected as a gain map when I queried it. I could probably force processing - and it isn't important as an ISO source is all we really need to support. I didn't dig deeply, but just thought I should note somewhere for future reference that the legacy XMP (on its own without ISO in the file) may not be supported. I don't see any need to dig further at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions