-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadImage.gs
More file actions
62 lines (43 loc) · 1.46 KB
/
loadImage.gs
File metadata and controls
62 lines (43 loc) · 1.46 KB
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
function loadImage() {
let selection = SlidesApp.getActivePresentation().getSelection();
let selectionRange = selection.getPageElementRange();
if(selectionRange == null)
throw "you need to select a image to reload the equation back into the text box"
let pageElements = selectionRange.getPageElements();
if(pageElements.length <= 0)
throw "please select a item"
else if(pageElements.length >= 2)
throw "can only select one item"
let image = pageElements[0].asImage()
let imageProps = getImageProps(image);
console.log("got here");
return {
"id": image.getObjectId(),
"imageProps": imageProps
};
}
function addImage(base64String, imageProps, imageId){
let image;
let newImageBlob = convertBase64StringToBlob(base64String);
var imageHeight = imageProps["height"];
if(imageId == "")
{
let slide = getCurrentSlide();
image = slide.insertImage(newImageBlob);
/*scale the image down, for some reason they make them very large when first added */
}
else
{
image = findImageSlide(imageId);
imageHeight = image.getHeight() * 2; //*2 because it's going to be divided bellow
image.replace(newImageBlob)
}
let h = image.getHeight();
let w = image.getWidth();
let r = w/h;
image.setHeight(imageHeight / 2);
image.setWidth(imageHeight * r / 2);
image.setTitle(Image_Title)
image.setDescription(JSON.stringify(imageProps));
return image.getObjectId();
}