diff --git a/vips/image.go b/vips/image.go index 85003e95..ec1ee177 100644 --- a/vips/image.go +++ b/vips/image.go @@ -1060,6 +1060,15 @@ func (r *ImageRef) ExtractBand(band int, num int) error { return nil } +// ExtractBandToImage extracts one or more bands out of the image to a new image +func (r *ImageRef) ExtractBandToImage(band int, num int) (*ImageRef, error) { + out, err := vipsExtractBand(r.image, band, num) + if err != nil { + return nil, err + } + return &ImageRef{image: out}, nil +} + // BandJoin joins a set of images together, bandwise. func (r *ImageRef) BandJoin(images ...*ImageRef) error { vipsImages := []*C.VipsImage{r.image} diff --git a/vips/image_golden_test.go b/vips/image_golden_test.go index 0dfb1aa9..5050fb0f 100644 --- a/vips/image_golden_test.go +++ b/vips/image_golden_test.go @@ -745,6 +745,13 @@ func TestImage_ExtractBand(t *testing.T) { }, nil, nil) } +func TestImage_ExtractBandToImage(t *testing.T) { + goldenTest(t, resources+"with_alpha.png", func(img *ImageRef) error { + _, err := img.ExtractBandToImage(2, 1) + return err + }, nil, nil) +} + func TestImage_Flatten(t *testing.T) { goldenTest(t, resources+"with_alpha.png", func(img *ImageRef) error { return img.Flatten(&Color{R: 32, G: 64, B: 128})