【问题标题】:Random image in Google slidesGoogle 幻灯片中的随机图像
【发布时间】:2021-11-21 00:39:32
【问题描述】:

如何将随机图片插入 Google 幻灯片?就像如果我使用一个链接,它总是会导致一个随机图像,我什至不知道一旦我出现图像会是什么。 -谢谢 (此链接可用于随机图片:https://source.unsplash.com/random/300x200

【问题讨论】:

  • 我必须为我糟糕的英语水平道歉。不幸的是,我无法理解您来自How could I insert a random image into Google Slides? like if I use a link, that always leads to a random image, to where I don't even know what the image will be once I present. 的问题。我可以问你问题的细节吗?
  • 感谢您的回复。这不是很多编码,这只是一个小问题。我只是想知道如何“在 Google 幻灯片上输入图像,每次展示幻灯片时都会发生变化”。 (更改为随机图像。)
  • 感谢您的回复。我不得不为我糟糕的英语水平道歉。不幸的是,我无法理解that changes every time you present the slide.。在您的情况下,当打开 Google 幻灯片时,您想更改图像吗?可以问一下具体情况吗?
  • 是的,完全正确。每次打开幻灯片的链接时,我都希望图像从互联网上的任何地方变为完全随机的图像。
  • 感谢您的回复。为了实现您的目标,需要从 URL 中检索第一张幻灯片和图像。在这种情况下,不能使用简单触发器的 OnOpen。而且,不幸的是,在当前阶段,Google 幻灯片无法使用可安装触发器的 OnOpen。这样一来,我认为在现阶段,你的目标是不能直接实现的。对此我深表歉意。

标签: google-slides


【解决方案1】:

正如@Tanaike 所说,您无法使用Simple Triggers 访问需要授权的资源。

他们无法访问需要授权的服务。

onOpen(e) 在这种情况下指向"https://www.googleapis.com/auth/script.external_request" 范围的简单触发器

作为一种解决方法,您可以使用Time Driven Installable Trigger 每天更改图像。

Code.gs
function changeImage() {
  let slideP = SlidesApp.getActivePresentation()
  let slide1 = slideP.getSlides()[0]
  let img = slide1.getImages()[0]
  // Fetch a new image 
  let req = UrlFetchApp.fetch('https://source.unsplash.com/random/300x200')
  let blobImage = req.getAs('image/jpeg')
  // Get the properties of the actual image
  let [left, top, width, height] = [
    img.getLeft(),
    img.getTop(),
    img.getWidth(),
    img.getHeight()
  ]
  // Remove the old one
  img.remove()
  // Add the new one with the same attributes
  slide1.insertImage(blobImage, left, top, width, height)
}

然后只需将函数添加到触发器。

【讨论】:

    猜你喜欢
    • 2016-05-04
    • 2021-01-18
    • 2013-03-10
    • 2016-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多