Skip to content

Instantly share code, notes, and snippets.

@northwestcoder
Last active July 24, 2020 13:05
Show Gist options
  • Save northwestcoder/9d8714e1e2c3662d70c455f436839076 to your computer and use it in GitHub Desktop.
Save northwestcoder/9d8714e1e2c3662d70c455f436839076 to your computer and use it in GitHub Desktop.
/** this script will not run correctly until imageFolderId is correctly set
*/
var imageFolderId = "REPLACEWITHYOURGOOGLEDRIVEFOLDERID";
var imageFolder = DriveApp.getFolderById(imageFolderId);
var NAME = 'My Vehicle Images';
var deck = SlidesApp.create(NAME);
/**
* Creates a single slide using the image from the given link;
* used directly by foreach(), hence the parameters are fixed.
* @param {string} imageUrl A String object representing an image URL
* @param {number} index The index into the array; unused (req'd by forEach)
*/
function addImageSlide(imageUrl, index) {
var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK);
var image = slide.insertImage(imageUrl);
var imgWidth = image.getWidth();
var imgHeight = image.getHeight();
var pageWidth = deck.getPageWidth();
var pageHeight = deck.getPageHeight();
var newX = pageWidth/2. - imgWidth/2.;
var newY = pageHeight/2. - imgHeight/2.;
image.setLeft(newX).setTop(newY);
}
/**
* Adds images to a slides presentation.
*/
function main() {
var images = [];
var contents = imageFolder.getFiles();
while (contents.hasNext()) {
var file = contents.next();
images.push(file)
}
var [title, subtitle] = deck.getSlides()[0].getPageElements();
title.asShape().getText().setText(NAME);
subtitle.asShape().getText().setText('Google Apps Script\nSlides Service demo');
images.forEach(addImageSlide);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment