[MUSIC]
WESLEY CHUN: Hey, developers.
Have you wondered how you can help your sales, marketing,
and business dev coworkers auto-generate slide
presentations out of a set of images?
Greetings and welcome to another episode of the G Suite show.
I'm your host, Wesley Chun.
Today we're going to show you how to do just that.
Slideshows have come a long way, from hand shadows in the cave
since fire was invented.
Then shadow puppetry of civilized men
to the magic lanterns of the 17th through 19th centuries.
And Uncle Bob's endless family vacation on 35-millimeter
slides.
And finally to today's generation
of tools like PowerPoint, Keynote,
and, of course, Google Slides.
While presentation software are end user applications,
some are programmable.
PowerPoint provides a COM server, where VB, C, or even
Python can be used to create PPT files or drive presentations.
Now we can take this to the cloud
by coding Google Slides with Apps Script, a customized
version of JavaScript that runs in Google's cloud,
giving you access to G Suite services, like slides.
As previously advertised, today's code sample
is a short script that creates a slide presentation
from a collection of images.
We're going to walk through a simple version
first, then add a few more lines to make it just
a little bit more useful.
Let's go to the computer now and take a look.
Jumping right in, we've got lines one
through two, which name your slide deck, both the file
name and the title of the presentation.
Line two specifically creates the slide deck.
Note the commented out part here.
We'll skip it for now, but we'll tell you what
it means before we wrap up.
Lines 4 through 7 is the add image slide function.
It takes a URL and index.
And we'll be using this with for each later.
For every image, we're going to add a new slide
and then insert the image.
The first part of main, from lines 9 to 16,
link to each image to create slides for.
17 to 19 grab the title and subtitle text boxes,
then sets the string values for both.
20 loops through the images, creating
slides for each by calling add image slide.
So if you save it and run it, you'll
see that it basically works.
After authorizing the script to gain access to your Google
Slides, you'll see in your drive folder
that it creates our presentation--
My favorite images.
And, if you open it up, you'll see
that we have all of our images, but in the upper left.
Not so great, right?
Let's get rid of this, and add seven more lines
to center the images, making it much more useful.
So what did we do?
The new lines, 7 through 10, grab the height and width
of each image, as well as the slide page.
Then 11 through 13 make the calculations
to center the image on both the x- and y-axes.
And that's it.
If we run this again, and take a look at the slide presentation,
you'll see we get another slide deck.
Nearly identical.
But the images are where we want them,
making this script and the slide decks it generates presentable
right away.
Isn't that cool?
And that's it.
As you saw, when it was just two major lines of code,
it did its job.
But adding a few more lines made it a lot better.
Well, if you want to dig deeper into the code
sample and the app itself, check out the corresponding tutorial.
Now this script is known as a standalone app,
because it's not tied to any specific document.
While standalone apps are useful for demos or personal use,
they're harder to share to a wider audience,
because the only way to do it is cut and paste.
Well, if you want to distribute your apps, this isn't scalable.
With a few changes, you can turn them
into add-ons, scripts that can be published publicly
for anyone to install, or privately
to your own G Suite domain.
Remember that line of code that was commented out?
Well, if you use that call, plus some additional required
boilerplate, you'll have an ad on that you can publish.
Check out the docs for more info.
Your next steps?
Well, you can jump straight into the docs
and brainstorm your own magic lantern app.
Or if you want to learn more about Apps Script?
Well, check out our other videos that show you
what else you can do with it.
Want to build an app for Google Slides
outside of the Apps Script environment
and with your own development tools?
Well, then, you want to use a slide's REST API.
And, of course, we've got another set of videos
to show you how to use that.
Got our sample app working?
Well, before you start on your own project,
I want to challenge you.
Instead of hard-coding online images,
well, tweak our app to use images on your Google Drive.
Or, even more powerful, use a drive file picker dialog,
and let your users choose.
Well, let us know how you do in the comments.
The sky's the limit on what you can
do with slides in Apps Script.
Thanks for tuning in.
And send us your suggestions on what
you'd like to see in future episodes down below.
This is Wesley Chun from Google, and we'll see you upstairs
in the G Suite.
[MUSIC PLAYING]