Colour shifts, missing ICC profiles, and CMYK distortion
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.
Inspect the generated outputs
Section titled “Inspect the generated outputs”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

{"operation":"source","target":"unchanged"}ICC: 568 bytesDownload generated output
{"operation":"stripped","target":"unchanged"}ICC: absentDownload generated output
{"operation":"converted","target":"sRGB"}ICC: 480 bytesDownload generated output| x | Reference input | Remove ICC without converting | Convert to sRGB first |
|---|---|---|---|
| 64 | 64, 64, 64 | 64, 64, 64 | 137, 137, 137 |
| 192 | 128, 32, 16 | 128, 32, 16 | 188, 99, 71 |
| 320 | 16, 128, 32 | 16, 128, 32 | 71, 188, 99 |
| 448 | 32, 16, 128 | 32, 16, 128 | 99, 71, 188 |
| 576 | 128, 128, 128 | 128, 128, 128 | 188, 188, 188 |
sharp 0.35.5 / libvips 8.18.7

{"operation":"keepIccProfile"}ICC: 568 bytesDownload generated output
{"operation":"remove iCCP before decode; no input ICC conversion"}ICC: absentDownload generated output
{"operation":"withIccProfile","target":"sRGB"}ICC: 480 bytesDownload generated output| x | Reference input | Remove ICC without converting | Convert to sRGB first |
|---|---|---|---|
| 64 | 64, 64, 64 | 64, 64, 64 | 137, 137, 137 |
| 192 | 128, 32, 16 | 128, 32, 16 | 188, 99, 71 |
| 320 | 16, 128, 32 | 16, 128, 32 | 71, 188, 99 |
| 448 | 32, 16, 128 | 32, 16, 128 | 99, 71, 188 |
| 576 | 128, 128, 128 | 128, 128, 128 | 188, 188, 188 |
pyvips 3.2.0 / libvips 8.17.3

{"operation":"retain embedded ICC"}ICC: 568 bytesDownload generated output
{"operation":"remove ICC without conversion"}ICC: absentDownload generated output
{"operation":"icc_transform","embedded":true,"target":"sRGB","intent":"perceptual"}ICC: 480 bytesDownload generated output| x | Reference input | Remove ICC without converting | Convert to sRGB first |
|---|---|---|---|
| 64 | 64, 64, 64 | 64, 64, 64 | 137, 137, 137 |
| 192 | 128, 32, 16 | 128, 32, 16 | 188, 99, 71 |
| 320 | 16, 128, 32 | 16, 128, 32 | 71, 188, 99 |
| 448 | 32, 16, 128 | 32, 16, 128 | 99, 71, 188 |
| 576 | 128, 128, 128 | 128, 128, 128 | 188, 188, 188 |
vipsCli 8.17.3 / libvips 8.17.3

{"operation":"copy; retain ICC"}ICC: 568 bytesDownload generated output
{"operation":"keep=none; no ICC transform"}ICC: absentDownload generated output
{"operation":"icc_transform srgb; embedded; perceptual"}ICC: 480 bytesDownload generated output| x | Reference input | Remove ICC without converting | Convert to sRGB first |
|---|---|---|---|
| 64 | 64, 64, 64 | 64, 64, 64 | 137, 137, 137 |
| 192 | 128, 32, 16 | 128, 32, 16 | 188, 99, 71 |
| 320 | 16, 128, 32 | 16, 128, 32 | 71, 188, 99 |
| 448 | 32, 16, 128 | 32, 16, 128 | 99, 71, 188 |
| 576 | 128, 128, 128 | 128, 128, 128 | 188, 188, 188 |
Read the three processing paths
Section titled “Read the three processing paths”| 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"]})
}Run command
node index.mjs linear-rgb.png output/Complete source
import sharp from 'sharp';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
const [input, out] = process.argv.slice(2);
if (!input || !out) throw new Error('usage: node index.mjs INPUT OUTPUT_DIRECTORY');
await mkdir(out, { recursive: true });
const outputs = [];
async function save(pipeline, name, parameters) {
await pipeline.toFile(path.join(out, name));
outputs.push({ path: name, parameters });
}
const buffer = await readFile(input);
// sharp normally performs input ICC conversion. For this deliberate failure,
// remove only the PNG iCCP chunk before decoding; other chunks and CRCs stay intact.
function withoutICC(png) {
if (png.subarray(0, 8).toString('hex') !== '89504e470d0a1a0a') throw new Error('expected PNG');
const chunks = [png.subarray(0, 8)];
for (let offset = 8; offset < png.length;) {
if (offset + 12 > png.length) throw new Error('truncated PNG chunk');
const end = offset + 12 + png.readUInt32BE(offset);
if (end > png.length) throw new Error('truncated PNG payload');
if (png.toString('ascii', offset + 4, offset + 8) !== 'iCCP') chunks.push(png.subarray(offset, end));
offset = end;
}
return Buffer.concat(chunks);
}
await save(sharp(buffer).keepIccProfile().png(), 'source.png', { operation: 'keepIccProfile' });
await save(sharp(withoutICC(buffer)).png(), 'stripped.png', { operation: 'remove iCCP before decode; no input ICC conversion' });
await save(sharp(buffer).withIccProfile('srgb').png(), 'converted.png', { operation: 'withIccProfile', target: 'sRGB' });
await writeFile(path.join(out, 'result.json'), JSON.stringify({ recipeId: 'colour-profile', input: path.basename(input), generator: { sharp: sharp.versions.sharp, libvips: sharp.versions.vips }, outputs }, null, 2) + '\n');Run command
python3 main.py linear-rgb.png output/Complete source
import json
from pathlib import Path
import sys
import pyvips
if len(sys.argv) != 3:
raise SystemExit("usage: python3 main.py INPUT OUTPUT_DIRECTORY")
source, out = Path(sys.argv[1]), Path(sys.argv[2])
out.mkdir(parents=True, exist_ok=True)
outputs = []
def record(name, parameters):
outputs.append({"path": name, "parameters": parameters})
image = pyvips.Image.new_from_file(str(source))
image.pngsave(str(out / "source.png"))
record("source.png", {"operation": "retain embedded ICC"})
wrong = image.copy()
wrong.remove("icc-profile-data")
wrong.pngsave(str(out / "stripped.png"))
record("stripped.png", {"operation": "remove ICC without conversion"})
image.icc_transform("srgb", embedded=True, intent="perceptual").pngsave(str(out / "converted.png"))
record("converted.png", {"operation": "icc_transform", "embedded": True, "target": "sRGB", "intent": "perceptual"})
(out / "result.json").write_text(json.dumps({"recipeId": "colour-profile", "input": source.name, "generator": {"pyvips": pyvips.__version__, "libvips": ".".join(str(pyvips.version(i)) for i in range(3))}, "outputs": outputs}, indent=2) + "\n")Run command
bash run.sh linear-rgb.png output/Complete source
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 2 ]]; then
echo 'usage: bash run.sh INPUT OUTPUT_DIRECTORY' >&2
exit 2
fi
input="$1"
out="$2"
mkdir -p "$out"
scratch="$(mktemp -d)"
trap 'rm -rf "$scratch"' EXIT
vips copy "$input" "$out/source.png"
vips copy "$input" "$out/stripped.png[keep=none]"
vips icc_transform "$input" "$out/converted.png" srgb --embedded --intent perceptual
python3 - "$input" "$out" <<'METADATA'
import json
from pathlib import Path
import subprocess
import sys
source, out = Path(sys.argv[1]), Path(sys.argv[2])
version = subprocess.check_output(["vips", "--version"], text=True).strip().removeprefix("vips-")
outputs = [{'path': 'source.png', 'parameters': {'operation': 'copy; retain ICC'}}, {'path': 'stripped.png', 'parameters': {'operation': 'keep=none; no ICC transform'}}, {'path': 'converted.png', 'parameters': {'operation': 'icc_transform srgb; embedded; perceptual'}}]
(out / "result.json").write_text(json.dumps({"recipeId": "colour-profile", "input": source.name, "generator": {"vipsCli": version, "libvips": version}, "outputs": outputs}, indent=2) + "\n")
METADATAVerify the correction
Section titled “Verify the correction”- Confirm the input has the intended ICC and record the working and target colour spaces.
- Inspect both ICC and pixels after loading, transformation, and export to locate profile removal or misinterpretation.
- Check target profile and grayscale samples together; merely copying an ICC blob is not a conversion.
- 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.
Verification boundary and sources
Section titled “Verification boundary and sources”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.