forked from KnicKnic/WASM-ImageMagick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
48 lines (40 loc) · 1.57 KB
/
index.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
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Rotate</title>
</head>
<body>
For license info of this project and related components see
<a href="https://github.com/knicknic/WASM-ImageMagick">https://github.com/knicknic/WASM-ImageMagick</a>
<BR>
<p>Source image: </p>
<img id="srcImage" src="rotate.png">
<BR>
<br>
<p>Rotated and enlarged image: </p>
<img id="rotatedImage">
<script type='module'>
//import the library to talk to imagemagick
import * as Magick from 'https://knicknic.github.io/wasm-imagemagick/magickApi.js';
// various html elements
let rotatedImage = document.getElementById('rotatedImage');
// Fetch the image to rotate, and call image magick
let DoMagickCall = async function () {
let fetchedSourceImage = await fetch("rotate.png");
let arrayBuffer = await fetchedSourceImage.arrayBuffer();
let sourceBytes = new Uint8Array(arrayBuffer);
// calling image magick with one source image, and command to rotate & resize image
const files = [{ 'name': 'srcFile.png', 'content': sourceBytes }];
const command = ["convert", "srcFile.png", "-rotate", "90", "-resize", "200%", "out.png"];
let processedFiles = await Magick.Call(files, command);
// response can be multiple files (example split)
// here we know we just have one
let firstOutputImage = processedFiles[0]
rotatedImage.src = URL.createObjectURL(firstOutputImage['blob'])
console.log("created image " + firstOutputImage['name'])
};
DoMagickCall();
</script>
</body>
</html>