Skip to content

Colour shifts, missing ICC profiles, and CMYK distortion

Copy page

Colour shifts can occur before encoding. Distinguish converting pixel values from deleting the ICC profile that describes their meaning. A controlled linear RGB sample makes the difference visible.

The sample contains colour patches and a grayscale gradient. It has sRGB primaries and a D65 white point, but a linear gamma-1.0 transfer curve. It is therefore neither ordinary sRGB nor a P3 or CMYK sample. Its embedded ICC profile describes that distinction.

In an ICC-aware browser, the tagged source and correctly converted sRGB output should look similar; removing the ICC without conversion will usually make the result darker. Browser, display, and colour management settings affect presentation, so the decoded RGB samples and ICC checks below establish what actually happened.

govips v2.20.0 / libvips 8.17.3

Reference input · govips · Reference
Reference input640 × 360, 5,979 bytes{"operation":"source","target":"unchanged"}ICC: 568 bytesDownload generated output
Remove ICC without converting · govips · Reference
Remove ICC without converting640 × 360, 5,620 bytes{"operation":"stripped","target":"unchanged"}ICC: absentDownload generated output
Convert to sRGB first · govips · Reference
Convert to sRGB first640 × 360, 5,531 bytes{"operation":"converted","target":"sRGB"}ICC: 480 bytesDownload generated output
Decoded RGB values at (x, 60)
xReference inputRemove ICC without convertingConvert to sRGB first
6464, 64, 6464, 64, 64137, 137, 137
192128, 32, 16128, 32, 16188, 99, 71
32016, 128, 3216, 128, 3271, 188, 99
44832, 16, 12832, 16, 12899, 71, 188
576128, 128, 128128, 128, 128188, 188, 188
Path Pixel and profile handling Verification
Retain the source Keep its linear RGB profile and pixels; sharp’s retain path permits one 8-bit level of roundtrip rounding Check ICC presence and compare the entire decoded image
Remove ICC directly Delete the profile without converting pixels; viewers commonly interpret the remaining values as sRGB Check missing ICC and unchanged pixels throughout the image
Convert to sRGB Recalculate pixels from the source ICC and embed the target profile Check changed pixels and target ICC; linear gray 64 becomes approximately sRGB 137, and 128 becomes approximately 188

Sharp normally performs input ICC conversion. Its deliberate failure case removes the PNG ICC chunk before decoding, rather than claiming ordinary sharp(...).png() must cause this shift. Every other entry also distinguishes deletion from conversion explicitly.

Convert explicitly and choose metadata handling

Section titled “Convert explicitly and choose metadata handling”

The target here is sRGB, using the embedded source ICC for the transformation. ICC presence alone does not prove conversion, and a colourspace interpretation conversion is not automatically equivalent to an ICC transform using the source profile.

The default WebP path in govips v2.20.0 retains the source ICC. With Keep unset, StripMetadata decides retention; explicit ForeignKeepIcc or ForeignKeepNone takes precedence. Retention options cannot replace a pixel colour transformation. This example uses PNG to isolate the relationship between profile and pixels, rather than establishing metadata defaults for every format.

Run command

go run . linear-rgb.png output/

Complete source

package main

import (
	"fmt"
	"os"

	"github.com/davidbyttow/govips/v2/vips"
	"github.com/webp-sh/vips-handbook/examples/internal/recipeutil"
)

func main() {
	if err := run(os.Args); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
func run(args []string) error {
	if len(args) != 3 {
		return fmt.Errorf("usage: main INPUT OUTPUT_DIRECTORY")
	}
	if err := os.MkdirAll(args[2], 0o755); err != nil {
		return err
	}
	if err := vips.Startup(nil); err != nil {
		return err
	}
	defer vips.Shutdown()
	outputs := []recipeutil.Output{}
	for _, id := range []string{"source", "stripped", "converted"} {
		output, err := makeVariant(args[1], args[2], id)
		if err != nil {
			return err
		}
		outputs = append(outputs, output)
	}
	return recipeutil.WriteResult(args[2], "colour-profile", args[1], outputs)
}

func makeVariant(input, dir, id string) (recipeutil.Output, error) {
	image, err := vips.NewImageFromFile(input)
	if err != nil {
		return recipeutil.Output{}, err
	}
	defer image.Close()
	if id == "stripped" {
		if err := image.RemoveICCProfile(); err != nil {
			return recipeutil.Output{}, err
		}
	}
	if id == "converted" {
		if err := image.TransformICCProfile("srgb"); err != nil {
			return recipeutil.Output{}, err
		}
	}
	return recipeutil.ExportPng(image, dir, id+".png", map[string]any{"operation": id, "target": map[bool]string{true: "sRGB", false: "unchanged"}[id == "converted"]})
}
  1. Confirm the input has the intended ICC and record the working and target colour spaces.
  2. Inspect both ICC and pixels after loading, transformation, and export to locate profile removal or misinterpretation.
  3. Check target profile and grayscale samples together; merely copying an ICC blob is not a conversion.
  4. If removing metadata, first complete the intended target conversion, then decide whether to retain its profile and verify in the actual viewing environment.

CMYK results depend on source and target profiles and rendering intent. “Resizing first always causes a colour shift” is not an adequate diagnosis: operation order depends on the working space and operations involved. This example establishes no CMYK conversion result.

Reviewed on 2026-10-26. Reference: govips v2.20.0 / libvips 8.17.3. Sharp 0.35.5 uses libvips 8.18.7; pyvips 3.2.0 and the CLI use libvips 8.17.3.

Coverage is limited to generated three-channel linear RGB, ICC removal, and conversion to sRGB. It excludes CMYK, P3, HDR, and comprehensive EXIF/IPTC stripping, and does not guarantee identical pixels between entries. See colour management and ICC for the underlying concepts.