Vips: Only call GetString() if interop index exists #5389

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2025-12-29 10:02:49 +01:00
parent 82c5989b30
commit 69acd58e12
2 changed files with 16 additions and 1 deletions

View file

@ -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)))
}

View file

@ -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