1 | <!DOCTYPE html>
|
2 | <html>
|
3 | <head>
|
4 | <title>Jimp browser example 4</title>
|
5 | </head>
|
6 | <body>
|
7 | <h1>Demonstrates how to write a text over an image</h1>
|
8 | <script src="../lib/jimp.js"></script>
|
9 | <img id="pic" style="float: left; margin: 0px 20px 5px 0px" />
|
10 | <script>
|
11 | function writePic() {
|
12 | Jimp.read("lenna.png")
|
13 | .then(function (lenna) {
|
14 | var fntName = "FONT_SANS_" + fntSize.value + "_" + txtColor.value;
|
15 | var x = parseInt(txtX.value);
|
16 | var y = parseInt(txtY.value);
|
17 | var w = parseInt(txtW.value);
|
18 | console.log();
|
19 | Jimp.loadFont(Jimp[fntName])
|
20 | .then(function (font) {
|
21 | lenna
|
22 | .print(font, x, y, txtField.value, w)
|
23 | .getBase64(Jimp.AUTO, function (err, src) {
|
24 | if (err) {
|
25 | alert(err.message);
|
26 | throw err;
|
27 | }
|
28 | pic.setAttribute("src", src);
|
29 | });
|
30 | })
|
31 | .catch(function (err) {
|
32 | throw err;
|
33 | });
|
34 | })
|
35 | .catch(function (err) {
|
36 | alert("Image load fail.\n" + err.message);
|
37 | throw err;
|
38 | });
|
39 | return false;
|
40 | }
|
41 | writePic();
|
42 | </script>
|
43 | <textarea rows="4" cols="80" id="txtField">Hi! I'm Lenna.</textarea>
|
44 | <br />
|
45 | <label
|
46 | >Size:
|
47 | <select id="fntSize">
|
48 | <option>8</option>
|
49 | <option>16</option>
|
50 | <option>32</option>
|
51 | <option>64</option>
|
52 | <option>128</option>
|
53 | </select></label
|
54 | >
|
55 | <br />
|
56 | <label
|
57 | >Color:
|
58 | <select id="txtColor">
|
59 | <option>BLACK</option>
|
60 | <option>WHITE</option>
|
61 | </select></label
|
62 | >
|
63 | <br />
|
64 | <label>pos X: <input id="txtX" value="0" size="3" />px</label> <br />
|
65 | <label>pos Y: <input id="txtY" value="0" size="3" />px</label> <br />
|
66 | <label>max Width: <input id="txtW" value="400" size="3" />px</label> <br />
|
67 | <input
|
68 | type="button"
|
69 | id="btWrite"
|
70 | onclick="writePic(); return false"
|
71 | value="Write"
|
72 | />
|
73 | </body>
|
74 | </html>
|