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

Please allow promise for transforms #88

Closed
cxa opened this issue May 7, 2021 · 1 comment
Closed

Please allow promise for transforms #88

cxa opened this issue May 7, 2021 · 1 comment

Comments

@cxa
Copy link
Contributor

cxa commented May 7, 2021

As the title, e.g. I need to extend transforms:

const extendTransforms = (builtins) => {
  const getBase64 = async (image) => {
    const img = image.resize({ width: 10 });
    const buf = await img.toBuffer();
    const mt = await img.metadata();
    return `data:image/${mt.format};base64,${buf.toString("base64")}`;
  };

  function base64(config, ctx) {
    if (config.width != "10") return;
    return async (image) => {
      setMetadata(image, "base64", await getBase64(image));
      return image;
    };
  }

  return [base64, ...builtins];
};
imagetools({ extendTransforms })
@JonasKruckenberg
Copy link
Owner

Absolutely! I already committed the change, it should go to npm in a couple minutes!
One caveat however: On the transform functions can be async, so

function blur() {
    return async () => {}
}

would work, but

async function blur() {
    return () => {}
}

would not. This shouldn't be a problem for most use cases though.

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

No branches or pull requests

2 participants