lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
29.11k stars 1.29k forks source link

Get operation progress information with handler function #2189

Open tchambard opened 4 years ago

tchambard commented 4 years ago

First of all, thanks for the great job done with sharp !!! It is a very powerful tool for images manipulation...

I would like to get some information about progression (percentage or weight) of current image operation (eg: crop, resize, tiles...)

I didn't found anything about this need in all existing issues...

I imagine a handler function injection like :

var transformer = sharp()
  .resize(300)
  .on('progress', function(progress) {
    console.log('Processing: ' + progress.percent + '% done');
  });

I know libvips consider an environment variable named VIPS_PROGRESS, so I guess there is something to do ?

lovell commented 4 years ago

By setting the VIPS_PROGRESS environment variable, which outputs percentage progress to stdout, you'll be able to assess how accurate this might be for a given operation.

Happy to accept a PR if you're able. This will require the use of AsyncProgressWorker and a minimum of N-API version 5, so would have to wait until we drop support for Node.js 10.