Merge images in Google Slides using Apps Script

In this tutorial, I will show you how to merge an image into a Google Slides presentation using Google Apps Script.

Automatically adding images to a presentation can be useful in many situations. For example, if you're a salesperson who likes to personalize the presentations that you create for your clients, you might want to add their logos to the presentation. It can be cumbersome to manually add these each time you make a presentation. You can become a lot more productive by automating this process and I will show you how to do that in this tutorial.

Here is what we want to do. Let's imagine that we have a presentation template that we've created in Google Slides. Maybe you have a title slide where you've created a placeholder for the logo. This placeholder is simply a rectangular shape inserted into the presentation with the text {{logo_image}} in it.

Screenshot of a slide in a presentation.

What we want to do is replace that placeholder with the actual logo image using Apps Script.

Screenshot of a slide in a presentation.

Here is the code to do that:

function mergeImageIntoGoogleSlides() {

 // Id of the presentation
 var templateId = "<SLIDES_ID>";

 //Logo url
 var logoUrl = "<LOGO_URL>";

 // Create the request to replace shapes in the
 // presentation with the logo. Any shape with the text
 // {{logo_image}} in it will be replaced with the image.
 var mergeImageRequests = [{
   replaceAllShapesWithImage: {
     imageUrl: logoUrl,
     containsText: {
       text: '{{logo_image}}'
     }
   }
 }];

 // Send the request to merge the logo into the presentation
 Slides.Presentations.batchUpdate({
   requests: mergeImageRequests
 }, templateId);
}

When you run the above function, the placeholder will be replaced with the image that you specified via logo_url.

Screenshot of a slide in a presentation.

Conclusion

In this tutorial, I show you how to merge an image into a Google Slides presentation using Apps Script. Thanks for reading!

Sign up to be notified when I publish new content

By signing up you agree to the Privacy Policy & Terms.