-
Notifications
You must be signed in to change notification settings - Fork 88
/
umd-test-nolibrary.html
88 lines (72 loc) · 2.39 KB
/
umd-test-nolibrary.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
<!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 without libraries </h1>
<p>in this case, when no libraries are detected the global variable <code>['wasm-imagemagick']</code> is available, so you can use it like this: </p>
<pre>
const { execute, loadImageElement, buildInputFile } = window['wasm-imagemagick']
</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="../../dist/bundles/wasm-imagemagick.umd-es5.js"></script>
<script>
const { execute, loadImageElement, buildInputFile } = window['wasm-imagemagick']
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>