From b02f2d89cdec0485637631880c7cb67e4becadd7 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sun, 13 Nov 2016 15:46:37 +0100 Subject: [PATCH 1/2] Testing the formats that cannot be saved Signed-off-by: Yoan Blanc --- vips_test.go | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/vips_test.go b/vips_test.go index 6456a54..95c6658 100644 --- a/vips_test.go +++ b/vips_test.go @@ -29,15 +29,36 @@ func TestVipsRead(t *testing.T) { } func TestVipsSave(t *testing.T) { - image, _, _ := vipsRead(readImage("test.jpg")) - options := vipsSaveOptions{Quality: 95, Type: JPEG, Interlace: true} + types := [...]ImageType{JPEG, PNG, TIFF, WEBP} - buf, err := vipsSave(image, options) - if err != nil { - t.Fatal("Cannot save the image") + for _, typ := range types { + image, _, _ := vipsRead(readImage("test.jpg")) + options := vipsSaveOptions{Quality: 95, Type: typ} + + buf, err := vipsSave(image, options) + if err != nil { + t.Fatalf("Cannot save the image as '%v'", ImageTypes[typ]) + } + if len(buf) == 0 { + t.Fatalf("Empty saved '%v' image", ImageTypes[typ]) + } } - if len(buf) == 0 { - t.Fatal("Empty image") +} + +func TestVipsCannotSave(t *testing.T) { + types := [...]ImageType{GIF, PDF, SVG, MAGICK} + + for _, typ := range types { + image, _, _ := vipsRead(readImage("test.jpg")) + options := vipsSaveOptions{Quality: 95, Type: typ} + + buf, err := vipsSave(image, options) + if err == nil { + t.Fatalf("Format '%v' shouldn't be supported", ImageTypes[typ]) + } + if len(buf) != 0 { + t.Fatalf("'%v' image is not empty", ImageTypes[typ]) + } } } From 5dd8611579d30ebc081adf7541dd0d4263c153b4 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Sun, 13 Nov 2016 15:47:33 +0100 Subject: [PATCH 2/2] Raise an error when trying to save as MAGICK type Signed-off-by: Yoan Blanc --- vips.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vips.go b/vips.go index 0553170..1bbd6ed 100644 --- a/vips.go +++ b/vips.go @@ -380,6 +380,8 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) { return nil, errors.New("VIPS cannot save to PDF") case SVG: return nil, errors.New("VIPS cannot save to SVG") + case MAGICK: + return nil, errors.New("VIPS cannot save to MAGICK") default: saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace) break