Generate Screenshots of Google Slides with Google Script
The new TallTweets app uses the Google Apps Script to convert Google Apps Script into GIF images. Internally, it uses the Google Slides API for generating screenshot images of individual slides of the presentation before stitching them into a GIF.
This Google Apps Script function uses the Advanced Slides API to generate high-resolution thumbnail images of the slides and uploads the individual slides to the Google Drive of the current user.
The public URLs of screenshot images are accessible for 30 minutes post which the URLs will expire automatically. The default mime type of the thumbnail image is PNG.
function generateScreenshots(presentationId) {
var presentation = SlidesApp.openById(presentationId);
var baseUrl = 'https://slides.googleapis.com/v1/presentations/{presentationId}/pages/{pageObjectId}/thumbnail';
var parameters = {
method: 'GET',
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
contentType: 'application/json',
muteHttpExceptions: true,
};
// Log URL of the main thumbnail of the deck
Logger.log(Drive.Files.get(presentationId).thumbnailLink);
// For storing the screenshot image URLs
var screenshots = [];
var slides = presentation.getSlides().forEach(function (slide, index) {
var url = baseUrl.replace('{presentationId}', presentationId).replace('{pageObjectId}', slide.getObjectId());
var response = JSON.parse(UrlFetchApp.fetch(url, parameters));
// Upload Googel Slide image to Google Drive
var blob = UrlFetchApp.fetch(response.contentUrl).getBlob();
DriveApp.createFile(blob).setName('Image ' + (index + 1) + '.png');
screenshots.push(response.contentUrl);
});
return screenshots;
}
Amit Agarwal
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.
Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory