aheckmann / gm

GraphicsMagick for node
http://aheckmann.github.com/gm/
6.95k stars 615 forks source link

Add support for promises #835

Open ajmas opened 3 years ago

ajmas commented 3 years ago

Looking at the docs and trying to use the project, it would seem there is no promise support.

Would this be something that could be of interest to add support for, and would contributions for this be welcome?

As an example of resulting usage change, with this:

before

gm('/path/to/my/img.jpg')
  .resize(240, 240)
  .noProfile()
  .write('/path/to/resize.png', function (err) {
    if (!err) console.log('done');
  });

after

try {
  await gm('/path/to/my/img.jpg')
    .resize(240, 240)
    .noProfile()
    .write('/path/to/resize.png');

  console.log('done');
} catch (err) {
  console.log(err);
}

For backwards compatibility, if a callback is provided then that is used, so something like:

if (callback) {
  callback(undefined, value);
} else {
  return value;
}