Saving to TIFF should also fail

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
master
Yoan Blanc 9 years ago
parent e099e4c9f5
commit 190fe92e28
No known key found for this signature in database
GPG Key ID: 6058CF4574298812

@ -8,6 +8,7 @@ import "C"
import ( import (
"errors" "errors"
"fmt"
"math" "math"
"os" "os"
"runtime" "runtime"
@ -370,21 +371,14 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
switch o.Type { switch o.Type {
case WEBP: case WEBP:
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, 1, quality) saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, 1, quality)
break
case PNG: case PNG:
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, 1, C.int(o.Compression), quality, interlace) saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, 1, C.int(o.Compression), quality, interlace)
break case 0:
case GIF: saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
return nil, errors.New("VIPS cannot save to GIF") case JPEG:
case PDF:
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) saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
break default:
return nil, fmt.Errorf("VIPS cannot save to %v.", ImageTypes[o.Type])
} }
if int(saveErr) != 0 { if int(saveErr) != 0 {

@ -29,7 +29,7 @@ func TestVipsRead(t *testing.T) {
} }
func TestVipsSave(t *testing.T) { func TestVipsSave(t *testing.T) {
types := [...]ImageType{JPEG, PNG, TIFF, WEBP} types := [...]ImageType{JPEG, PNG, WEBP}
for _, typ := range types { for _, typ := range types {
image, _, _ := vipsRead(readImage("test.jpg")) image, _, _ := vipsRead(readImage("test.jpg"))
@ -46,7 +46,7 @@ func TestVipsSave(t *testing.T) {
} }
func TestVipsCannotSave(t *testing.T) { func TestVipsCannotSave(t *testing.T) {
types := [...]ImageType{GIF, PDF, SVG, MAGICK} types := [...]ImageType{GIF, MAGICK, PDF, SVG, TIFF}
for _, typ := range types { for _, typ := range types {
image, _, _ := vipsRead(readImage("test.jpg")) image, _, _ := vipsRead(readImage("test.jpg"))
@ -118,9 +118,9 @@ func TestVipsWatermark(t *testing.T) {
t.Errorf("Cannot add watermark: %s", err) t.Errorf("Cannot add watermark: %s", err)
} }
buf, _ := vipsSave(newImg, vipsSaveOptions{Quality: 95}) buf, err := vipsSave(newImg, vipsSaveOptions{Quality: 95})
if len(buf) == 0 { if len(buf) == 0 || err != nil {
t.Fatal("Empty image") t.Fatalf("Empty image. %#v", err)
} }
} }

Loading…
Cancel
Save