dailylog 9-14-20
How to Get Images to Google Slides
TL;DR:
- Generate files (using some naming convention so you just have to loop 1-119 or whatever)
- Use Filezilla to upload them to a domain
- Use this script inside google.scripts (subbing out your image urls of course – which you generated using a simple loop see below)
Google Scripts Script
var NAME = "ALL MY SLIDES!!";
var presentation = 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 = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK);
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);
}
/**
* The driver application features an array of image URLs, setting of the
* main title & subtitle, and creation of individual slides for each image.
*/
function main() {
images = [
"http://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
"http://www.google.com/services/images/phone-animation-results_2x.png",
"http://www.google.com/services/images/section-work-card-img_2x.jpg",
"http://gsuite.google.com/img/icons/product-lockup.png",
"http://gsuite.google.com/img/home-hero_2x.jpg",
];
var [title, subtitle] = presentation.getSlides()[0].getPageElements();
title.asShape().getText().setText(NAME);
subtitle.asShape().getText().setText("You made this?\nI made this.");
images.forEach(addImageSlide);
}
Simple Link Gen Loop
for i in range(49):
img = "'https://my-cat-farm-is-kool.com/folder/filename_" + str(i)+".png',"
print(img)
THINGS I TRIED BEFORE THIS:
PROBLEM: I have hundreds of images that need to go into a slide show! Far too many to do by hand!!
SOLUTION: Automate that! With automator?!
PROBLEM: On a mac, automator stopped working with Power Point with Office 2016…
SOLUTION: What if I convert all of the images to PDFs? Can’t I batch import PDFS?
PROBLEM: Oh wait, I haven’t installed Imagemagik on this machine yet…
SOLUTION: FREAKING INSTALL IT YAAAAH!!!
PROBLEM: This is not the original problem we are trying to solve, is it? Might there be an easier way?
SOLUTION: Yes! Yes there is an extension for Google Slides!
PROBLEM: It imports them, but not in the correct order. Yes, we wasted a whole $3 on this.
SOLUTION: Can we write our own google script to do this?
YES! YES WE CAN!!!
PROBLEM: The basic script (the one without forms or Google Drive authentication) require the images to be hosted somewhere online…
SOLUTION: Use one of my MANY dreamhost accounts!!!!
PROBLEM: The one I’ve ensured is secure (read here using encryption and port 22) has three domains, two of which are now defunct
POTENTIAL SOLUTION: Renew these domains
POTENTIAL PROBLEM: Get lost on the endless “why do I have so many domains OH WAIT YES YES THIS FUN PROJECT!!” side quest
SOLUTION: Simply host a folder you know you will delete on the one domain that IS working, even though it is hosting a project your friends are using…