Insert images from Google Drive into Google Slides using Apps Script
In this tutorial, I'll show you how easy it is to programmatically insert images from Google Drive into a Google Slides presentation using Apps Script.
In fact, this is so easy to do that the Apps Script code is just a few lines long!
Prerequisites
This tutorial assumes that you're familiar with:
Here is the code to get an image from Drive an insert it into a Google Slides presentation:
Note
Remember to replace <SLIDES_ID>
in the code with the actual Id of your Google Slides presentation. You can get the Id from the URL of the presentation.
https://docs.google.com/presentation/d/<SLIDES_ID>/edit
Also, please replace <DRIVE_FILE_ID>
in the code with the Id of the image in Google Drive.
https://drive.google.com/file/d/<DRIVE_FILE_ID>/view?usp=sharing
function insertImageFromDrive() {
// Load the image from Google Drive
var image = DriveApp.getFileById("<DRIVE_FILE_ID>");
// Load the Google Slides presentation.
var presentation = SlidesApp.openById("<SLIDES_ID>");
// Insert the image into the first slide of your presentation.
presentation.getSlides()[0].insertImage(image);
}
When you run the insertImageFromDrive()
function, the image will be inserted into the first slide in your presentation.
Conclusion
In this tutorial, I showed you how easy it is to insert images from Google Drive into a Google Slides presentation using Apps Script.