-
Notifications
You must be signed in to change notification settings - Fork 86
/
umd-test-requirejs.html
96 lines (77 loc) · 2.67 KB
/
umd-test-requirejs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>test dist/bundles/index.esm.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<style>
textarea{
width: 100%;
height: 250px;
}
input{
width: 100%
}
</style>
<h1>Testing wasm-imagemagick.umd-es5.js with require-js </h1>
<p>When AMD libraries like requirejs or almondjs are present, the library can be accessed like this: </p>
<pre>
require(['wasm-imagemagick'], function (WasmImagemagick) {
const { execute, loadImageElement, buildInputFile } = WasmImagemagick
</pre>
<div>
<p>Image URL: </p>
<input id="imageUrl" type="text" value="../rotate/FriedrichNietzsche.png">
</div>
<div>
<p>Commands. </p>
<textarea id="commandText">
convert FriedrichNietzsche.png -rotate 33 -resize 100x90! out.png
convert out.png -charcoal 1 charcoal1.gif
convert out.png -charcoal 2 charcoal2.gif
convert \
charcoal1.gif \
\( \
-clone 0 charcoal2.gif -compose difference \
-composite -threshold 5% -fill red \
-opaque white -transparent black \
\) \
-compose over -composite \
pcharcoaldiff.png
</textarea>
</div>
<button id="execute">Execute</button>
<div id="imagesContainer"></div>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script> -->
<script src="https://unpkg.com/[email protected]/almond.js"></script>
<script src="../../dist/bundles/wasm-imagemagick.umd-es5.js"></script>
<script>
require(['wasm-imagemagick'], function (WasmImagemagick) {
const { execute, loadImageElement, buildInputFile } = WasmImagemagick
async function renderImages(images) {
document.querySelector('#imagesContainer').innerHTML = ''
images.forEach(async imageFile => {
const container = document.createElement('div')
container.innerText = `"${imageFile.name}" : `
const img = document.createElement('img')
img.alt = img.title = imageFile.name
container.appendChild(img)
document.querySelector('#imagesContainer').appendChild(container)
await loadImageElement(imageFile, img)
})
}
async function main() {
const input = await buildInputFile(document.querySelector('#imageUrl').value)
const commands = document.querySelector('#commandText').value
const result = await execute({ inputFiles: [input], commands })
await renderImages([input].concat(result.outputFiles))
}
document.querySelector('#execute').addEventListener('click', main)
main()
})
</script>
</body>
</html>