MCPcopy Index your code
hub / github.com/methodofaction/Method-Draw / importImageFile

Function importImageFile

src/js/Image.js:13–49  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

11 }
12
13 function importImageFile(file) {
14
15 reader.onloadend = function(e) {
16 // lets insert the new image until we know its dimensions
17 insertNewImage = function(img_width, img_height){
18 var newImage = svgCanvas.addSvgElementFromJson({
19 "element": "image",
20 "attr": {
21 "x": 0,
22 "y": 0,
23 "width": img_width,
24 "height": img_height,
25 "id": svgCanvas.getNextId(),
26 "style": "pointer-events:inherit"
27 }
28 });
29 svgCanvas.setHref(newImage, e.target.result);
30 svgCanvas.selectOnly([newImage])
31 svgCanvas.alignSelectedElements("m", "page")
32 svgCanvas.alignSelectedElements("c", "page")
33 updateContextPanel();
34 }
35 // put a placeholder img so we know the default dimensions
36 var img_width = 100;
37 var img_height = 100;
38 var img = new Image()
39 img.src = e.target.result
40 document.body.appendChild(img);
41 img.onload = function() {
42 img_width = img.offsetWidth
43 img_height = img.offsetHeight
44 insertNewImage(img_width, img_height);
45 document.body.removeChild(img);
46 }
47 };
48 reader.readAsDataURL(file)
49 }
50
51 function importSvgFile(file){
52 reader.onloadend = function(e) {

Callers 1

importImageFunction · 0.85

Calls 1

updateContextPanelFunction · 0.85

Tested by

no test coverage detected