1 | <!DOCTYPE html>
|
2 | <html>
|
3 | <head>
|
4 | <title>Jimp browser example 1</title>
|
5 | </head>
|
6 | <body>
|
7 |
|
8 | <script src="../lib/jimp.min.js"></script>
|
9 | <script>
|
10 | function dropShadow(x, y, b, a) {
|
11 | var img = new Jimp(
|
12 | this.bitmap.width + Math.abs(x * 2) + b * 2,
|
13 | this.bitmap.height + Math.abs(y * 2) + b * 2
|
14 | );
|
15 | var orig = this.clone();
|
16 | this.scan(
|
17 | 0,
|
18 | 0,
|
19 | this.bitmap.width,
|
20 | this.bitmap.height,
|
21 | function (x, y, idx) {
|
22 | this.bitmap.data[idx + 0] = 0;
|
23 | this.bitmap.data[idx + 1] = 0;
|
24 | this.bitmap.data[idx + 2] = 0;
|
25 | this.bitmap.data[idx + 3] = this.bitmap.data[idx + 3] * a;
|
26 | }
|
27 | );
|
28 |
|
29 |
|
30 | var x1 = Math.max(x * -1, 0) + b;
|
31 | var y1 = Math.max(y * -1, 0) + b;
|
32 | img.composite(this, x1, y1);
|
33 | img.blur(b);
|
34 | img.composite(orig, x1 - x, y1 - y);
|
35 |
|
36 | return img;
|
37 | }
|
38 | Jimp.read("dice.png").then(function (img) {
|
39 | console.log(img.getMIME(), img.getExtension());
|
40 | var img = dropShadow.call(img, 20, 20, 20, 0.3);
|
41 | img.getBase64(Jimp.AUTO, function (err, src) {
|
42 | var img = document.createElement("img");
|
43 | img.setAttribute("src", src);
|
44 | document.body.appendChild(img);
|
45 | });
|
46 | });
|
47 | </script>
|
48 | </body>
|
49 | </html>
|