1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-02-07 11:36:25 +02:00

Fix animated JPEG XL support

This commit is contained in:
DarthSim 2024-12-08 21:07:36 +03:00
parent 9d955444df
commit d9abf2d3d7
5 changed files with 13 additions and 9 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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:

View File

@ -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);