I would like to create a Google Slides presentation out of a folder of images on my local Google Drive, within Google Script. I want to label each one individually to give them a particular order in the presentation and attach a Boolean value for later use.
I first tried adapting the code from the Example in the Google Developers video: https://www.youtube.com/watch?v=rTDz-Zcn7yk.
This works, but he just alludes to being able to show images from a personal Google Drive without an explanation for how.
I then tried combining the Google Developer's code with the one created by Learn Google Spreadsheets video: https://www.youtube.com/watch?v=PTOKHjVkXYs.
Here, he's trying to create a spreadsheet with information from a local Google drive folder containing images. This got me closer to an answer, but I run into similar trouble trying to pass the folder's images into an array and passing them through .insertImage();
Here is the code I attempted to create by trying to combine these two. I am assuming I am not retrieving the correct data from my getMyFiles function and copying them to my AfileLabels array. Maybe instead of .getName it should use a .get that can return the imageUrl from my local drive, but I don't know how to do that. I also can't seem to pass that array to my final line: images.forEach(addImageSlide);. I'm also sure there is a much simpler way to create my fileLabel arrays than iteratively making them like I did, but I don't know how to do that.
var NAME = "My Presentation";
var deck = SlidesApp.create(NAME);
function getMyFiles() {
var myFolders = DriveApp;
var i = 0;
var j = 0;
var AfileLabels = new Array();
var AfileLabels = [];
var BfileLabels = new Array();
var BfileLabels = [];
var AfolderIter = myFolders.getFoldersByName("A");
var Afolder = AfolderIter.next();
var AfolderIter = Afolder.getFiles();
while(AfolderIter.hasNext()) {
var Afile = AfolderIter.next();
var AfileName = Afile.getName();
Logger.log(AfileName);
AfileLabels[i] = AfileName;
i++;
}
var i = 0;
Logger.log(AfileLabels);
var BfolderIter = myFolders.getFoldersByName("B");
var Bfolder = BfolderIter.next();
var BfolderIter = Bfolder.getFiles();
while(BfolderIter.hasNext()) {
var Bfile = BfolderIter.next();
var BfileName = Bfile.getName();
Logger.log(BfileName);
BfileLabels[i] = BfileName;
j++;
}
var j = 0;
Logger.log(BfileLabels);
}
function addImageSlide(AfileLabels, index) {
var slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK);
var image = slide.insertImage(AfileLabels);
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 AfileLabels = new Array();
var AfileLabels = [];
var AfileLabels = getMyFiles();
Logger.log(AfileLabels);
var images = ASfileLabels;
var [title, subtitle] = deck.getSlides()[0].getPageElements();
title.asShape().getText().setText(NAME);
subtitle.asShape().getText().setText("Subtitle for Presentation");
images.forEach(addImageSlide);
}
What functions am I using incorrectly? How do I pass my array of images through to images?