MCPcopy
hub / github.com/jimp-dev/jimp / shadow

Function shadow

plugins/plugin-shadow/src/index.ts:28–60  ·  view source on GitHub ↗

* Adds a shadow to the image

(image: I, options: ShadowOptions = {})

Source from the content-addressed store, hash-verified

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};

Callers

nothing calls this directly

Calls 3

cloneFunction · 0.90
compositeFunction · 0.90
resizeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…