Skip to content

Commit

Permalink
feat: Allow ImageTransform functions to be async
Browse files Browse the repository at this point in the history
Closes #88. This change allows transform functions to return a Promise as well.
  • Loading branch information
JonasKruckenberg committed May 7, 2021
1 parent d1e03d1 commit da3e726
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/lib/apply-transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export async function applyTransforms(transforms: ImageTransformation[], image:
image.withMetadata()
}

image = transforms.reduce((img, transform) => transform(img), image)
for (const transform of transforms) {
image = await transform(image)
}

return {
image,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type TransformFactory<A = {}> = (metadata: Partial<ImageConfig & A>, ctx:

export type TransformOption<A = {},T = any> = (metadata: Partial<ImageConfig & A>, image: Sharp) => T | undefined

export type ImageTransformation = (image: Sharp) => Sharp
export type ImageTransformation = (image: Sharp) => Sharp | Promise<Sharp>

export interface TransformResult {
image: Sharp,
Expand Down

0 comments on commit da3e726

Please sign in to comment.