mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 13:38:16 -08:00
Add GIF save support from libvips 8.12
This commit is contained in:
parent
78145aa405
commit
2f73f4d9e0
4 changed files with 39 additions and 5 deletions
|
|
@ -21,9 +21,18 @@ func TestImageResize(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageGifResize(t *testing.T) {
|
func TestImageGifResize(t *testing.T) {
|
||||||
_, err := initImage("test.gif").Resize(300, 240)
|
if VipsMajorVersion >= 8 && VipsMinorVersion >= 12 {
|
||||||
if err == nil {
|
buf, err := initImage("test.gif").Resize(300, 240)
|
||||||
t.Errorf("GIF shouldn't be saved within VIPS")
|
if err != nil {
|
||||||
|
t.Errorf("Cannot process the image: %#v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = assertSize(buf, 300, 240)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Write("testdata/test_resize_out.gif", buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ func TestIsTypeSupportedSave(t *testing.T) {
|
||||||
types := []struct {
|
types := []struct {
|
||||||
name ImageType
|
name ImageType
|
||||||
}{
|
}{
|
||||||
{JPEG}, {PNG}, {WEBP},
|
{JPEG}, {PNG}, {WEBP}, {GIF},
|
||||||
}
|
}
|
||||||
if VipsVersion >= "8.5.0" {
|
if VipsVersion >= "8.5.0" {
|
||||||
types = append(types, struct{ name ImageType }{TIFF})
|
types = append(types, struct{ name ImageType }{TIFF})
|
||||||
|
|
@ -136,6 +136,9 @@ func TestIsTypeSupportedSave(t *testing.T) {
|
||||||
if VipsVersion >= "8.9.0" {
|
if VipsVersion >= "8.9.0" {
|
||||||
types = append(types, struct{ name ImageType }{AVIF})
|
types = append(types, struct{ name ImageType }{AVIF})
|
||||||
}
|
}
|
||||||
|
if VipsVersion >= "8.12.0" {
|
||||||
|
types = append(types, struct{ name ImageType }{GIF})
|
||||||
|
}
|
||||||
|
|
||||||
for _, n := range types {
|
for _, n := range types {
|
||||||
if IsTypeSupportedSave(n.name) == false {
|
if IsTypeSupportedSave(n.name) == false {
|
||||||
|
|
@ -152,11 +155,11 @@ func TestIsTypeNameSupportedSave(t *testing.T) {
|
||||||
{"jpeg", true},
|
{"jpeg", true},
|
||||||
{"png", true},
|
{"png", true},
|
||||||
{"webp", true},
|
{"webp", true},
|
||||||
{"gif", false},
|
|
||||||
{"pdf", false},
|
{"pdf", false},
|
||||||
{"tiff", VipsVersion >= "8.5.0"},
|
{"tiff", VipsVersion >= "8.5.0"},
|
||||||
{"heif", VipsVersion >= "8.8.0"},
|
{"heif", VipsVersion >= "8.8.0"},
|
||||||
{"avif", VipsVersion >= "8.9.0"},
|
{"avif", VipsVersion >= "8.9.0"},
|
||||||
|
{"gif", VipsVersion >= "8.12.0"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, n := range types {
|
for _, n := range types {
|
||||||
|
|
|
||||||
5
vips.go
5
vips.go
|
|
@ -230,6 +230,9 @@ func VipsIsTypeSupportedSave(t ImageType) bool {
|
||||||
if t == AVIF {
|
if t == AVIF {
|
||||||
return int(C.vips_type_find_save_bridge(C.HEIF)) != 0
|
return int(C.vips_type_find_save_bridge(C.HEIF)) != 0
|
||||||
}
|
}
|
||||||
|
if t == GIF {
|
||||||
|
return int(C.vips_type_find_save_bridge(C.GIF)) != 0
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -524,6 +527,8 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
saveErr = C.vips_heifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
|
saveErr = C.vips_heifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
|
||||||
case AVIF:
|
case AVIF:
|
||||||
saveErr = C.vips_avifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless, speed)
|
saveErr = C.vips_avifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless, speed)
|
||||||
|
case GIF:
|
||||||
|
saveErr = C.vips_gifsave_bridge(tmpImage, &ptr, &length, strip)
|
||||||
default:
|
default:
|
||||||
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, strip, quality, interlace)
|
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, strip, quality, interlace)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
vips.h
17
vips.h
|
|
@ -185,6 +185,11 @@ vips_type_find_save_bridge(int t) {
|
||||||
if (t == HEIF) {
|
if (t == HEIF) {
|
||||||
return vips_type_find("VipsOperation", "heifsave_buffer");
|
return vips_type_find("VipsOperation", "heifsave_buffer");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 12))
|
||||||
|
if (t == GIF) {
|
||||||
|
return vips_type_find("VipsOperation", "gifsave_buffer");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -407,6 +412,18 @@ vips_heifsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int qual
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
vips_gifsave_bridge(VipsImage *in, void **buf, size_t *len, int strip) {
|
||||||
|
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 12))
|
||||||
|
return vips_gifsave_buffer(in, buf, len,
|
||||||
|
"strip", INT_TO_GBOOLEAN(strip),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips_is_16bit (VipsInterpretation interpretation) {
|
vips_is_16bit (VipsInterpretation interpretation) {
|
||||||
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
|
return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue