Skip to content

Commit 6dde215

Browse files
committed
insert inline image
Signed-off-by: Alex Ivanov <ai@contributor.pw>
1 parent 969f693 commit 6dde215

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"timeZone": "Europe/Moscow",
3+
"exceptionLogging": "STACKDRIVER",
4+
"runtimeVersion": "V8"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "container-bound-doc",
3+
"src": []
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {GoogleAppsScript.Document.InlineImage} docImage
3+
* @returns {GoogleAppsScript.Document.InlineImage} docImage
4+
*/
5+
const scaleImage_ = (docImage, { width = undefined, height = undefined }) => {
6+
const factor = docImage.getHeight() / docImage.getWidth();
7+
if (width && height) docImage.setWidth(width).setHeight(height);
8+
else if (width) {
9+
docImage.setWidth(width).setHeight(width * factor);
10+
} else docImage.setWidth(height / factor).setHeight(height);
11+
return docImage;
12+
};
13+
14+
/**
15+
*
16+
*/
17+
function run() {
18+
const image = DriveApp.getFileById('1nVNdbt9SY42c-A30X5iSK4RaMcKCk2pt');
19+
const paragraph = DocumentApp.getActiveDocument()
20+
.getBody()
21+
.getTables()[0]
22+
.getRow(0)
23+
.getCell(1)
24+
.getChild(0)
25+
.asParagraph(); // The paragraph in a specific cell
26+
const inlineImage = paragraph.insertInlineImage(0, image.getBlob());
27+
scaleImage_(inlineImage, { width: 200 });
28+
}

0 commit comments

Comments
 (0)