-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathmake_image.htm
115 lines (101 loc) · 4.09 KB
/
make_image.htm
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test svg/png/jpeg creation in the browser</title>
<link rel="shortcut icon" href="../img/RootIcon.ico"/>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: 20px 300px 20px 300px 20px 300px 20px;
gap: 2px;
background-color: #968;
padding: 2px;
height: 100%;
}
.grid-container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 0 0;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Example usage of makeImage function</h1>
<div class="grid-container">
<div>2D drawing</div>
<div>3D drawing</div>
<div>Geo drawing</div>
<div id="draw_svg1"></div>
<div id="draw_svg2"></div>
<div id="draw_svg3"></div>
<div id="info_svg1"></div>
<div id="info_svg2"></div>
<div id="info_svg3"></div>
<div id="draw_png1"></div>
<div id="draw_png2"></div>
<div id="draw_png3"></div>
<div id="info_png1"></div>
<div id="info_png2"></div>
<div id="info_png3"></div>
<div id="draw_jpeg1"></div>
<div id="draw_jpeg2"></div>
<div id="draw_jpeg3"></div>
<div id="info_jpeg1"></div>
<div id="info_jpeg2"></div>
<div id="info_jpeg3"></div>
</div>
</body>
<script type='module'>
import { openFile, makeImage } from '../modules/main.mjs';
const width = 400, height = 300;
function makeColumn(id, object, option) {
makeImage({ format: 'svg', object, option, width, height })
.then(svg => {
// svg is just string with code which directly can be set to HTML element
if (!svg) return;
document.getElementById(`draw_svg${id}`).innerHTML = svg;
document.getElementById(`info_svg${id}`).innerHTML = `SVG image size ${svg.length}`;
});
makeImage({ format: 'png', object, option, width, height })
.then(png => {
// png in base64 format is provided
if (!png) return;
let img = new Image;
img.src = png;
document.getElementById(`draw_png${id}`).appendChild(img);
document.getElementById(`info_png${id}`).innerHTML = `PNG image base64 ${png.length}`;
// shows also binary buffer can be generated as well
makeImage({ format: 'png', as_buffer: true, object, option, width, height }).then(buf => {
// such buffer can be stored in the file
document.getElementById(`info_png${id}`).innerHTML += ` buf ${buf.byteLength}`;
});
});
makeImage({ format: 'jpeg', object, option, width, height })
.then(jpeg => {
// jpeg in base64 format provided
if (!jpeg) return;
let img = new Image;
img.src = jpeg;
document.getElementById(`draw_jpeg${id}`).appendChild(img);
document.getElementById(`info_jpeg${id}`).innerHTML = `JPEG image base64 ${jpeg.length}`;
// shows also binary buffer can be generated as well
makeImage({ format: 'jpeg', as_buffer: true, object, option, width, height }).then(buf => {
// such buffer can be stored in the file
document.getElementById(`info_jpeg${id}`).innerHTML += ` buf ${buf.byteLength}`;
});
});
}
openFile('https://root.cern/js/files/hsimple.root')
.then(file => file.readObject('hpxpy;1'))
.then(hpxpy => {
makeColumn('1', hpxpy, 'col');
makeColumn('2', hpxpy, 'lego2');
});
openFile('https://root.cern/js/files/geom/rootgeom.root')
.then(file => file.readObject('simple1;1'))
.then(geom => makeColumn('3', geom, ''));
</script>
</html>