export_color_profile.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package processing
  2. import (
  3. "github.com/imgproxy/imgproxy/v3/imagedata"
  4. "github.com/imgproxy/imgproxy/v3/options"
  5. "github.com/imgproxy/imgproxy/v3/vips"
  6. )
  7. func exportColorProfile(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
  8. keepProfile := !po.StripColorProfile && po.Format.SupportsColourProfile()
  9. if pctx.iccImported {
  10. if keepProfile {
  11. // We imported ICC profile and want to keep it,
  12. // so we need to export it
  13. if err := img.ExportColourProfile(); err != nil {
  14. return err
  15. }
  16. } else {
  17. // We imported ICC profile but don't want to keep it,
  18. // so we need to export image to sRGB for maximum compatibility
  19. if err := img.ExportColourProfileToSRGB(); err != nil {
  20. return err
  21. }
  22. }
  23. } else if !keepProfile {
  24. // We don't import ICC profile and don't want to keep it,
  25. // so we need to transform it to sRGB for maximum compatibility
  26. if err := img.TransformColourProfile(); err != nil {
  27. return err
  28. }
  29. }
  30. if err := img.RgbColourspace(); err != nil {
  31. return err
  32. }
  33. if !keepProfile {
  34. return img.RemoveColourProfile()
  35. }
  36. return nil
  37. }