mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-14 18:05:55 -07:00
commit
ebc0ee815f
2 changed files with 30 additions and 7 deletions
2
vips.go
2
vips.go
|
|
@ -380,6 +380,8 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
return nil, errors.New("VIPS cannot save to PDF")
|
return nil, errors.New("VIPS cannot save to PDF")
|
||||||
case SVG:
|
case SVG:
|
||||||
return nil, errors.New("VIPS cannot save to SVG")
|
return nil, errors.New("VIPS cannot save to SVG")
|
||||||
|
case MAGICK:
|
||||||
|
return nil, errors.New("VIPS cannot save to MAGICK")
|
||||||
default:
|
default:
|
||||||
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
|
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace)
|
||||||
break
|
break
|
||||||
|
|
|
||||||
35
vips_test.go
35
vips_test.go
|
|
@ -29,15 +29,36 @@ func TestVipsRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVipsSave(t *testing.T) {
|
func TestVipsSave(t *testing.T) {
|
||||||
image, _, _ := vipsRead(readImage("test.jpg"))
|
types := [...]ImageType{JPEG, PNG, TIFF, WEBP}
|
||||||
options := vipsSaveOptions{Quality: 95, Type: JPEG, Interlace: true}
|
|
||||||
|
|
||||||
buf, err := vipsSave(image, options)
|
for _, typ := range types {
|
||||||
if err != nil {
|
image, _, _ := vipsRead(readImage("test.jpg"))
|
||||||
t.Fatal("Cannot save the image")
|
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])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue