Error using keepGainMap() + keepMetadata()
bug
@lovell Great to see [keepGainMap()](https://github.com/lovell/sharp/issues/4314#issuecomment-4191094196) 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:
```js
sharp(input).keepGainMap().keepMetadata().jpeg({ quality: 90 })
```
fails for gain-map JPEG input with:
```txt
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](https://github.com/user-attachments/files/26577192/sample.gain.maps.zip)
- Node.js v20.12.2
- `sharp` 0.35.0-rc.2
- libvips 8.18.2
### Example
```js
import sharp from "sharp";
const input = "myGainMap.jpg";
await sharp(input)
.keepGainMap()
.keepMetadata()
.jpeg({ quality: 90 })
.toBuffer();
```
### Actual result
```txt
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:
```js
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:
```js
await sharp(input)
.keepMetadata()
.keepGainMap()
.jpeg({ quality: 90 })
.toBuffer();
```
关闭于 2026-04-10 1 条评论