[英]How do get GIF from Google Docs using Apps Script?
I want to get the gif image from google docs.我想从谷歌文档中获取 gif 图像。 Using Apps Script, gif images are got as InlineImage.使用 Apps Script,gif 图像被作为 InlineImage 获得。 But it's only static without animating.但它只是静态的,没有动画。
My code我的代码
var doc = DocumentApp.openByUrl('url');
Logger.log(doc.getBody().getImages()[0]);
var encoded = Utilities.base64Encode(doc.getBody().getImages()[0].getBlob().getBytes());
Logger.log(encoded);
If my understanding is correct, how about this answer?如果我的理解是正确的,这个答案怎么样? Please think of this as just one of several possible answers.请将此视为几种可能的答案之一。
Unfortunately, it seems that the original images cannot be directly retrieved using getImages()
.不幸的是,似乎无法使用getImages()
直接检索原始图像。 So in this answer, I use the method of documents.get in Google Docs API.所以在这个答案中,我使用了Google Docs API 中的documents.get 方法。
The flow of this sample script is as follows.此示例脚本的流程如下。
inlineObjects
.嵌入的原始图像可以从inlineObjects
的属性中inlineObjects
。Before you use this script, please enable Google Docs API at Advanced Google services.在使用此脚本之前, 请在高级 Google 服务中启用 Google Docs API。
function myFunction() {
var documentId = "###"; // Please set Google Document ID.
// Retrieve the object from Google Document using the method of documents.get in Google Docs API.
var obj = Docs.Documents.get(documentId);
// Retrieve the source information from the retrieved object.
var inlineObjects = Object.keys(obj.inlineObjects).reduce(function(ar, e, i) {
var o = obj.inlineObjects[e].inlineObjectProperties.embeddedObject;
if (o.hasOwnProperty("imageProperties")) {
var res = UrlFetchApp.fetch(o.imageProperties.contentUri, {headers: {Authorization: "Baerer " + ScriptApp.getOAuthToken()}, muteHttpExceptions: true});
if (res.getResponseCode() == 200) ar.push(res.getBlob().setName("image" + (i + 1)));
}
return ar;
}, []);
// Create the original images from the retrieved source information.
inlineObjects.forEach(function(blob) {
var id = DriveApp.createFile(blob).getId();
Logger.log(id)
})
}
If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.