作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的目标是根据文件夹中的图像自动创建和更新 Google 幻灯片演示文稿:
当前工作正常但我想自动化的工作流程如下:
var NAME = "Dynamic Image Insert Test";
var presentation = SlidesApp.create(NAME);
function addImageSlide(fileID, index) {
var slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK);
var imageurl = DriveApp.getFileById(fileID);
var image = slide.insertImage(imageurl);
var imgWidth = image.getWidth();
var imgHeight = image.getHeight();
var pageWidth = presentation.getPageWidth();
var pageHeight = presentation.getPageHeight();
var newX = pageWidth/2. - imgWidth/2.;
var newY = pageHeight/2. - imgHeight/2.;
image.setLeft(newX).setTop(newY);
}
function main() {
var images = [
"Insert ID of a File 1 on Google Drive here",
"Insert ID of a File 2 on Google Drive here"
];
var [title, subtitle] = presentation.getSlides()[0].getPageElements();
title.asShape().getText().setText(NAME);
subtitle.asShape().getText().setText("Insert Files from Drive using File ID");
images.forEach(addImageSlide);
}
{
"pageElements": [
{
"transform": {
"scaleX": 171.123,
"scaleY": 171.123,
"unit": "EMU",
"translateY": 1288327.54,
"translateX": 2375975
},
"objectId": "MyImage_01",
"image": {
"sourceUrl": "https://lh3.google.com/u/0/d/This-is-the-static-file-id",
"contentUrl": "https://lh6.googleusercontent.com/This-is-the-id-created-when-creating-the-image-on-the-slide",
"imageProperties": {
"shadow": {
"color": {
"rgbColor": {}
},
"blurRadius": {
"unit": "EMU"
},
"type": "OUTER",
"transform": {
"scaleX": 1,
"scaleY": 1,
"unit": "EMU"
},
"alpha": 1,
"propertyState": "NOT_RENDERED",
"rotateWithShape": false,
"alignment": "BOTTOM_LEFT"
},
"outline": {
"dashStyle": "SOLID",
"propertyState": "NOT_RENDERED",
"weight": {
"unit": "EMU",
"magnitude": 9525
},
"outlineFill": {
"solidFill": {
"color": {
"themeColor": "DARK2"
},
"alpha": 1
}
}
}
}
},
"size": {
"width": {
"unit": "EMU",
"magnitude": 23375
},
"height": {
"unit": "EMU",
"magnitude": 15000
}
}
}
]
}
最佳答案
我已使用此脚本更新一张幻灯片上的所有图像。我目前正在考虑在用户通过 Google 表单加载图像时自动执行此功能。也许这可以帮助您解决问题。
/////////////////////////////////////////
var deck = SlidesApp.getActivePresentation()
var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK)
function main() {
var folder = DriveApp.getFolderById('your folder id goes here'); // Change the folder
ID here
var files = folder.getFiles();
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
var imageUrl = DriveApp.getFileById(file.getId()).getDownloadUrl() + "&access_token="
+ ScriptApp.getOAuthToken();
Logger.log(DriveApp.getFileById(file.getId()).getDownloadUrl() + "&access_token=" +
ScriptApp.getOAuthToken());
var image = slide.insertImage(imageUrl);
}}
////////////////////////////////////
关于google-apps-script - 在 Google 云端硬盘中更新图片时更新 Google 幻灯片中的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48851334/
我是一名优秀的程序员,十分优秀!