|
|
import { isNodePattern } from "@jimp/utils"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default () => ({ |
|
|
shadow(options = {}, cb) { |
|
|
if (typeof options === "function") { |
|
|
cb = options; |
|
|
options = {}; |
|
|
} |
|
|
|
|
|
const { opacity = 0.7, size = 1.1, x = -25, y = 25, blur = 5 } = options; |
|
|
|
|
|
|
|
|
const orig = this.clone(); |
|
|
const shadow = this.clone(); |
|
|
|
|
|
|
|
|
shadow.scan( |
|
|
0, |
|
|
0, |
|
|
shadow.bitmap.width, |
|
|
shadow.bitmap.height, |
|
|
(x, y, idx) => { |
|
|
shadow.bitmap.data[idx] = 0x00; |
|
|
shadow.bitmap.data[idx + 1] = 0x00; |
|
|
shadow.bitmap.data[idx + 2] = 0x00; |
|
|
|
|
|
shadow.bitmap.data[idx + 3] = shadow.constructor.limit255( |
|
|
shadow.bitmap.data[idx + 3] * opacity |
|
|
); |
|
|
|
|
|
this.bitmap.data[idx] = 0x00; |
|
|
this.bitmap.data[idx + 1] = 0x00; |
|
|
this.bitmap.data[idx + 2] = 0x00; |
|
|
this.bitmap.data[idx + 3] = 0x00; |
|
|
} |
|
|
); |
|
|
|
|
|
|
|
|
shadow |
|
|
.resize(shadow.bitmap.width * size, shadow.bitmap.height * size) |
|
|
.blur(blur); |
|
|
|
|
|
|
|
|
this.composite(shadow, x, y); |
|
|
this.composite(orig, 0, 0); |
|
|
|
|
|
if (isNodePattern(cb)) { |
|
|
cb.call(this, null, this); |
|
|
} |
|
|
|
|
|
return this; |
|
|
}, |
|
|
}); |
|
|
|