diff --git a/process.go b/process.go index a013b2d7..f40bf8db 100644 --- a/process.go +++ b/process.go @@ -524,7 +524,7 @@ func processImage(ctx context.Context) ([]byte, error) { } defer C.clear_image(&img) - if imgtype == imageTypeGIF && po.Format == imageTypeGIF { + if imgtype == imageTypeGIF && po.Format == imageTypeGIF && vipsIsAnimatedGif(img) { if err := transformGif(ctx, &img, po); err != nil { return nil, err } @@ -682,6 +682,10 @@ func vipsArrayjoin(in []*C.struct__VipsImage, out **C.struct__VipsImage) error { return nil } +func vipsIsAnimatedGif(img *C.struct__VipsImage) bool { + return C.vips_is_animated_gif(img) > 0 +} + func vipsImageHasAlpha(img *C.struct__VipsImage) bool { return C.vips_image_hasalpha_go(img) > 0 } diff --git a/vips.h b/vips.h index 8719d6af..ae1c60b8 100644 --- a/vips.h +++ b/vips.h @@ -148,6 +148,13 @@ vips_band_format(VipsImage *in) { return in->BandFmt; } +gboolean +vips_is_animated_gif(VipsImage * in) { + return( vips_image_get_typeof(in, "page-height") != G_TYPE_INVALID && + vips_image_get_typeof(in, "gif-delay") != G_TYPE_INVALID && + vips_image_get_typeof(in, "gif-loop") != G_TYPE_INVALID ); +} + gboolean vips_image_hasalpha_go(VipsImage * in) { #if VIPS_SUPPORT_HASALPHA