#4608·sharp

默认情况下保留源色彩空间,但可以明确选择退出

作者: gregbenz创建于 2026年9月17日更新于 2026年9月17日
标签enhancement

When you searched for similar feature requests, what did you find that might be related?

  • #218 discusses preserving non-sRGB color spaces and acknowledges gamut loss from converting P3 to sRGB.
  • #1323 covers custom output ICC profiles and color spaces.
  • #3824 and PR #3856 introduced explicit controls such as keepIccProfile(), while deliberately retaining the existing defaults. Those discussions provide opt-in preservation. This request proposes making preservation the default, with an explicit opt-out. Applications that prefer sRGB output should retain an explicit way to request the current behavior, which is included in the proposal below.

What would you expect the API to look like?

No additional call should be needed to preserve a valid embedded ICC profile. Ordinary processing should behave as though .keepIccProfile() were enabled by default, wherever the operation and output format support it. Images without an embedded profile would retain their existing behavior. Explicit output color-space or profile requests, including .withIccProfile(...), would continue to take precedence. There should also be an explicit opt-out that retains today's behavior: convert to sRGB and omit the profile. It should not simply remove the profile from unchanged non-sRGB pixels. I would defer the opt-out method's name to the maintainers' preferred API conventions.

What alternatives have you considered?

Applications can already call keepIccProfile(), but developers must know to request it. The loss of wide-gamut colors may go unnoticed when testing on an sRGB-only display. This example compares the current default with explicit profile preservation:

bash
node <<'NODE'
const sharp = require('sharp');

(async () => {
  await sharp('input-p3.jpg')
    .jpeg({ quality: 100 })
    .toFile('out-default-srgb.jpg'); // Current default: converts to sRGB, reducing the gamut of this P3 image.
  await sharp('input-p3.jpg')
    .keepIccProfile()
    .jpeg({
…