mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 21:48:13 -08:00
Saving to TIFF should also fail
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
parent
e099e4c9f5
commit
190fe92e28
2 changed files with 11 additions and 17 deletions
18
vips.go
18
vips.go
|
|
@ -8,6 +8,7 @@ import "C"
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
|
|
@ -370,21 +371,14 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
|||
switch o.Type {
|
||||
case WEBP:
|
||||
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, 1, quality)
|
||||
break
|
||||
case PNG:
|
||||
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, 1, C.int(o.Compression), quality, interlace)
|
||||
break
|
||||
case GIF:
|
||||
return nil, errors.New("VIPS cannot save to GIF")
|
||||
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:
|
||||
case 0:
|
||||
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
|
||||
break
|
||||
case JPEG:
|
||||
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
|
||||
default:
|
||||
return nil, fmt.Errorf("VIPS cannot save to %v.", ImageTypes[o.Type])
|
||||
}
|
||||
|
||||
if int(saveErr) != 0 {
|
||||
|
|
|
|||
10
vips_test.go
10
vips_test.go
|
|
@ -29,7 +29,7 @@ func TestVipsRead(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVipsSave(t *testing.T) {
|
||||
types := [...]ImageType{JPEG, PNG, TIFF, WEBP}
|
||||
types := [...]ImageType{JPEG, PNG, WEBP}
|
||||
|
||||
for _, typ := range types {
|
||||
image, _, _ := vipsRead(readImage("test.jpg"))
|
||||
|
|
@ -46,7 +46,7 @@ func TestVipsSave(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 {
|
||||
image, _, _ := vipsRead(readImage("test.jpg"))
|
||||
|
|
@ -118,9 +118,9 @@ func TestVipsWatermark(t *testing.T) {
|
|||
t.Errorf("Cannot add watermark: %s", err)
|
||||
}
|
||||
|
||||
buf, _ := vipsSave(newImg, vipsSaveOptions{Quality: 95})
|
||||
if len(buf) == 0 {
|
||||
t.Fatal("Empty image")
|
||||
buf, err := vipsSave(newImg, vipsSaveOptions{Quality: 95})
|
||||
if len(buf) == 0 || err != nil {
|
||||
t.Fatalf("Empty image. %#v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue