* Adds a shadow to the image
(image: I, options: ShadowOptions = {})
| 26 | * Adds a shadow to the image |
| 27 | */ |
| 28 | shadow<I extends JimpClass>(image: I, options: ShadowOptions = {}) { |
| 29 | const { |
| 30 | opacity: opacityAmount = 0.7, |
| 31 | size = 1.1, |
| 32 | x = -25, |
| 33 | y = 25, |
| 34 | blur: blurAmount = 5, |
| 35 | } = ShadowOptionsSchema.parse(options); |
| 36 | |
| 37 | // clone the image |
| 38 | const orig = clone(image); |
| 39 | let shadow = clone(image); |
| 40 | // enlarge it. This creates a "shadow". |
| 41 | shadow = resizeMethods.resize(shadow, { |
| 42 | w: image.bitmap.width * size, |
| 43 | h: image.bitmap.height * size, |
| 44 | }); |
| 45 | shadow = blurMethods.blur(shadow, blurAmount); |
| 46 | shadow = colorMethods.opacity(shadow, opacityAmount); |
| 47 | |
| 48 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 49 | const blankImage = new (image.constructor as any)({ |
| 50 | width: image.bitmap.width, |
| 51 | height: image.bitmap.height, |
| 52 | color: 0x00000000, |
| 53 | }); |
| 54 | |
| 55 | // Then blit the "shadow" onto the background and the image on top of that. |
| 56 | let result = composite(blankImage, orig, 0, 0); |
| 57 | result = composite(result, shadow, x, y); |
| 58 | |
| 59 | return result; |
| 60 | }, |
| 61 | }; |