Have been trying to do a few presentations containing text and images (mostly images).
.
Main aim is to be able to plan the questions and answers on Sheets, to then transfer onto Slides.
. https://docs.google.com/spreadsheets/d/1Qp8kS_Bw_MNKs1Q55VsxF9cHqk1aXVZrVRA80x3aK-I/edit?usp=sharing .
function myFunction() {
var searchText = "{{CENTERED_SHAPE}}";
///// hoping to get the image from Google Sheets instead of the URL
var imageUrl = "http://gsuite.google.com/img/icons/product-lockup.png";
// 1. Retrieve 1st slide.
var presentation = SlidesApp.getActivePresentation();
var slide = presentation.getSlides()[0];
// 2. Replace the shape which has the text of "searchText" with the image of "imageUrl".
slide.getShapes().forEach(s => {
if (s.getText().asString().toLocaleUpperCase().includes(searchText.toLocaleUpperCase())) {
s.replaceWithImage(imageUrl);
}
});
}
.
Have searched for a solution and closest was:
function snapScreenshot(presentationId) {
var row = 11;
var col = 2;
var siteUrl = sheet.getRange(row, col).getValue()
var url = "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=" + encodeURIComponent(siteUrl) + "&key=" + pageSpeedApiKey;
var res = UrlFetchApp.fetch(url).getContentText()
var obj = JSON.parse(res);
var imgData = obj.lighthouseResult.audits['final-screenshot'].details.data;
var strImage = imgData.replace(/^data:image\/[a-z]+;base64,/, "")
var blob = Utilities.newBlob(Utilities.base64Decode(strImage), "image/jpeg", "sample.jpeg");
var presentation = SlidesApp.openById(presentationId)
var page = presentation.getSlideById(slide_id)
var position = {left:230, top: 87};
var size = {width: 600, height: 220}
page.insertImage(blob, position.left, position.top, size.width, size.height)
This, however, is for a screenshot and can't quite figure out how to extract the image from Sheets and place in a Slide.
.
Is there a way to do so?
***Edit
Have taken a look at examples given on:
How to access new 'in-cell-image' from google apps script?
but have not found the solution in mind.
Would like to be able to somehow .getImage/copy the image from its cell in Sheets and paste/place it into Slides.
Much appreciated, DDS