diff --git a/imagetype/imagetype.go b/imagetype/imagetype.go index f1e5df34..0c0f17d8 100644 --- a/imagetype/imagetype.go +++ b/imagetype/imagetype.go @@ -147,7 +147,11 @@ func (it Type) SupportsAlpha() bool { return it != JPEG && it != BMP } -func (it Type) SupportsAnimation() bool { +func (it Type) SupportsAnimationLoad() bool { + return it == GIF || it == WEBP || it == JXL +} + +func (it Type) SupportsAnimationSave() bool { return it == GIF || it == WEBP } diff --git a/processing/processing.go b/processing/processing.go index d88866eb..54bdc658 100644 --- a/processing/processing.go +++ b/processing/processing.go @@ -54,7 +54,7 @@ func isImageTypePreferred(imgtype imagetype.Type) bool { func findBestFormat(srcType imagetype.Type, animated, expectAlpha bool) imagetype.Type { for _, t := range config.PreferredFormats { - if animated && !t.SupportsAnimation() { + if animated && !t.SupportsAnimationSave() { continue } @@ -248,8 +248,8 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options animationSupport := po.SecurityOptions.MaxAnimationFrames > 1 && - imgdata.Type.SupportsAnimation() && - (po.Format == imagetype.Unknown || po.Format.SupportsAnimation()) + imgdata.Type.SupportsAnimationLoad() && + (po.Format == imagetype.Unknown || po.Format.SupportsAnimationSave()) pages := 1 if animationSupport { @@ -304,7 +304,7 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options return nil, fmt.Errorf("Can't save %s, probably not supported by your libvips", po.Format) } - if po.Format.SupportsAnimation() && animated { + if po.Format.SupportsAnimationSave() && animated { if err := transformAnimated(ctx, img, po, imgdata); err != nil { return nil, err } diff --git a/vips/vips.c b/vips/vips.c index 417f9977..1bcc4cde 100644 --- a/vips/vips.c +++ b/vips/vips.c @@ -64,9 +64,9 @@ vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out) } int -vips_jxlload_go(void *buf, size_t len, VipsImage **out) +vips_jxlload_go(void *buf, size_t len, int pages, VipsImage **out) { - return vips_jxlload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, NULL); + return vips_jxlload_buffer(buf, len, out, "access", VIPS_ACCESS_SEQUENTIAL, "n", pages, NULL); } int diff --git a/vips/vips.go b/vips/vips.go index 0415e20e..bc001830 100644 --- a/vips/vips.go +++ b/vips/vips.go @@ -337,7 +337,7 @@ func (img *Image) Load(imgdata *imagedata.ImageData, shrink int, scale float64, case imagetype.JPEG: err = C.vips_jpegload_go(data, dataSize, C.int(shrink), &tmp) case imagetype.JXL: - err = C.vips_jxlload_go(data, dataSize, &tmp) + err = C.vips_jxlload_go(data, dataSize, C.int(pages), &tmp) case imagetype.PNG: err = C.vips_pngload_go(data, dataSize, &tmp, vipsConf.PngUnlimited) case imagetype.WEBP: diff --git a/vips/vips.h b/vips/vips.h index 5c7aa920..9a4b2314 100644 --- a/vips/vips.h +++ b/vips/vips.h @@ -16,7 +16,7 @@ int gif_resolution_limit(); int vips_health(); int vips_jpegload_go(void *buf, size_t len, int shrink, VipsImage **out); -int vips_jxlload_go(void *buf, size_t len, VipsImage **out); +int vips_jxlload_go(void *buf, size_t len, int pages, VipsImage **out); int vips_pngload_go(void *buf, size_t len, VipsImage **out, int unlimited); int vips_webpload_go(void *buf, size_t len, double scale, int pages, VipsImage **out); int vips_gifload_go(void *buf, size_t len, int pages, VipsImage **out);