Reduce memory usage when scaling down animated images

This commit is contained in:
DarthSim
2024-01-27 18:34:21 +03:00
parent 4684abf0c0
commit 880d16f457
4 changed files with 16 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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