Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress information #63

Closed
swissspidy opened this issue Jan 27, 2024 · 3 comments
Closed

Add progress information #63

swissspidy opened this issue Jan 27, 2024 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@swissspidy
Copy link

On the command line --vips-progress runs a progress indicator during computation. It can be useful to see where libvips is looping and how often.

I wonder if it's possible to expose progress in a similar way in wasm-vips, for example by adding an option to provide a callback function that gets called with the current progress. That way, if an operation takes a bit longer, one can display a progress bar to users as well.

@kleisauke kleisauke added the enhancement New feature or request label Jan 28, 2024
@kleisauke kleisauke added this to the v0.0.8 milestone Jan 28, 2024
@kleisauke
Copy link
Owner

Good idea! I just implemented this with commit c004099, allowing you to do this:

// Load a huge image
const im = vips.Image.black(100000, 100000);

// Attach progress feedback
let lastPercent = 0;
im.onProgress = (percent) => {
  // This callback is triggered once per work unit (typically a 128 x
  // 128 area of pixels) during image computation. Therefore, we only
  // need to print when there's a change in the percentage.
  if (percent !== lastPercent) {
    console.log(`${percent}% complete`);
    lastPercent = percent;
  }

  // To stop long-running computations, we could block evaluation after a
  // certain amount of time. To avoid complexity in this example, issue the
  // kill signal after 25% completion.
  if (percent >= 25) {
    im.kill = true;
  }
};

// Save
im.writeToFile('x.png');

I also made it possible to stop long-running computations with commit 20f8414, as shown in the example above.

This will be in v0.0.8.

@swissspidy
Copy link
Author

This is fantastic, thanks a lot for this fast response & implementation!

Looking forward to implementing both in my project.

@kleisauke
Copy link
Owner

v0.0.8 is now available with these improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants