func minTransparency(image *vips.Image) (float64, error) { if !image.HasAlpha() { return 1.0, nil } band, err := image.Copy() if err != nil { return 0, err } defer band.Close() if err := band.ExtractBand(band.ImageGetBands()-1, 1); err != nil { return 0, err } // If all pixels are at least 90% opaque, we can flatten. min, err := band.Min() if err != nil { return 0, err } return min / band.MaxAlpha(), nil }