diff --git a/CHANGELOG.md b/CHANGELOG.md index be88c45f..365caa26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Don't set `Expires` HTTP header as it is ignored if the `Cache-Control` header is set. - Don't log health-check requests and responses. - Enforce `IMGPROXY_WORKERS=1` when running in AWS Lambda. +- Reduce memory usage when scaling down animated images. - (pro) If the `step` argument of the `video_thumbnail_tile` is negative, calculate `step` automatically. ### Fix diff --git a/processing/processing.go b/processing/processing.go index 97888c3d..35ba8c13 100644 --- a/processing/processing.go +++ b/processing/processing.go @@ -162,6 +162,16 @@ func transformAnimated(ctx context.Context, img *vips.Image, po *options.Process if err = mainPipeline.Run(ctx, frame, po, nil); err != nil { return err } + + if r, _ := frame.GetIntDefault("imgproxy-scaled-down", 0); r == 1 { + if err = frame.CopyMemory(); err != nil { + return err + } + + if err = router.CheckTimeout(ctx); err != nil { + return err + } + } } if err = img.Arrayjoin(frames); err != nil { diff --git a/vips/vips.c b/vips/vips.c index 0923d55f..df756302 100644 --- a/vips/vips.c +++ b/vips/vips.c @@ -804,7 +804,7 @@ vips_strip(VipsImage *in, VipsImage **out, int keep_exif_copyright) (strcmp(name, "vips-loader") == 0) || (strcmp(name, "background") == 0) || (strcmp(name, "vips-sequential") == 0) || - (strcmp(name, "imgproxy-dpr-scale") == 0)) + (vips_isprefix("imgproxy-", name))) continue; if (keep_exif_copyright) { diff --git a/vips/vips.go b/vips/vips.go index 642792b7..2c825968 100644 --- a/vips/vips.go +++ b/vips/vips.go @@ -606,6 +606,10 @@ func (img *Image) Resize(wscale, hscale float64) error { return Error() } + if wscale < 1.0 || hscale < 1.0 { + C.vips_image_set_int(tmp, cachedCString("imgproxy-scaled-down"), 1) + } + C.swap_and_clear(&img.VipsImage, tmp) return nil