diff --git a/internal/thumb/vips.go b/internal/thumb/vips.go index fdf712911..a45a62269 100644 --- a/internal/thumb/vips.go +++ b/internal/thumb/vips.go @@ -79,6 +79,7 @@ func Vips(imageName string, imageBuffer []byte, hash, thumbPath string, width, h // Use defaults. } + // Embed an ICC profile when a JPEG declares its color space via the EXIF InteroperabilityIndex tag. if err = vipsSetIccProfileForInteropIndex(img, clean.Log(filepath.Base(imageName))); err != nil { log.Debugf("vips: %s in %s (set icc profile for interop index tag)", err, clean.Log(filepath.Base(imageName))) } diff --git a/internal/thumb/vips_icc.go b/internal/thumb/vips_icc.go index bc63246a2..d58bada98 100644 --- a/internal/thumb/vips_icc.go +++ b/internal/thumb/vips_icc.go @@ -30,7 +30,21 @@ func vipsSetIccProfileForInteropIndex(img *vips.ImageRef, logName string) (err e // Some cameras signal color space via EXIF InteroperabilityIndex instead of // embedding an ICC profile. Browsers and libvips ignore this tag, so we // inject a matching ICC profile to produce correct thumbnails. - iiFull := img.GetString("exif-ifd4-InteroperabilityIndex") + iiField := "exif-ifd4-InteroperabilityIndex" + hasInterop := false + + for _, field := range img.GetFields() { + if field == iiField { + hasInterop = true + break + } + } + + if !hasInterop { + return nil + } + + iiFull := img.GetString(iiField) if iiFull == "" { return nil