Get image urls from Slide
If you ever wanted to get a list of all image urls in some presentation, this little AppsScript can be helpfull.
- Go to https://script.google.com
- Click New project
- Replace the content in Code.gs with this
1function getImages() {
2 slidesUrl = "URL_TO_SLIDE";
3 try {
4
5 // Initialize an array to hold the output data
6 var outputData = [];
7 outputData.push(["Slides URL", "Slide index", "Image URL"]); // Header row
8 // Get the Slides presentation by URL.
9 var presentation = SlidesApp.openByUrl(slidesUrl);
10
11 // Get all the slides in the presentation.
12 var slides = presentation.getSlides();
13
14 for (var index = 0; index < slides.length; index = index + 1) {
15 slide = slides[index];
16
17 // Get all page elements on the slide.
18 var pageElements = slide.getPageElements();
19
20 var imageUrls = [];
21 // Iterate through the page elements.
22 for (var i = 0; i < pageElements.length; i++) {
23 var pageElement = pageElements[i];
24
25 // Check if the element is an image.
26 if (pageElement.getPageElementType() == SlidesApp.PageElementType.IMAGE) {
27 var image = pageElement.asImage();
28 var imageUrl = image.getContentUrl(); // .getImageUrl();
29 if (imageUrl) {
30 imageUrls.push(imageUrl)
31 }
32 outputData.push([slidesUrl, i, imageUrl])
33 }
34 }
35 }
36 // Create a new spreadsheet to write the data
37 var ss = SpreadsheetApp.create("Image urls from Slide");
38 var sheet = ss.getActiveSheet();
39
40 // Write the output data to the spreadsheet
41 sheet.getRange(1, 1, outputData.length, outputData[0].length).setValues(outputData);
42
43 Logger.log("Spreadsheet URL: " + ss.getUrl())
44
45 } catch (error) {
46 Logger.log("Error: " + error);
47 return []; // Return an empty array if there's an error (e.g., invalid URL).
48 }
49}
Save and then Run the script
The log will show any errors and end with the link to a new Sheet containing the information.