Google apps script Google应用程序脚本在doGet函数中返回图像
我不知道如何在谷歌应用程序脚本中返回图像。我也查阅了很多文档,但找不到任何清晰的内容 在PHP中,等效函数为:Google apps script Google应用程序脚本在doGet函数中返回图像,google-apps-script,Google Apps Script,我不知道如何在谷歌应用程序脚本中返回图像。我也查阅了很多文档,但找不到任何清晰的内容 在PHP中,等效函数为: header('Content-Type: image/gif'); echo "\x47\x49\x46\x38\x37\x61\x1\x0\x1\x0\x80\x0\x0\xfc\x6a\x6c\x0\x0\x0\x2c\x0\x0\x0\x0\x1\x0\x1\x0\x0\x2\x2\x44\x1\x0\x3b"; 我尝试过以下函数: function doGet() {
header('Content-Type: image/gif');
echo "\x47\x49\x46\x38\x37\x61\x1\x0\x1\x0\x80\x0\x0\xfc\x6a\x6c\x0\x0\x0\x2c\x0\x0\x0\x0\x1\x0\x1\x0\x0\x2\x2\x44\x1\x0\x3b";
我尝试过以下函数:
function doGet() {
return ContentService.createTextOutput("\x47\x49\x46\x38\x37\x61\x1\x0\x1\x0\x80\x0\x0\xfc\x6a\x6c\x0\x0\x0\x2c\x0\x0\x0\x0\x1\x0\x1\x0\x0\x2\x2\x44\x1\x0\x3b");
}
}
但它似乎不起作用。我基本上想要返回1x1像素的图像。谷歌应用程序脚本只支持返回纯文本、ATOM、CSV、iCal、JavaScript、JSON、RSS、vCard和XML内容
这取决于您的用户情况,但您可以使用和数据URI方案来嵌入图像:
GS:
function doGet(e) {
template = HtmlService.createTemplateFromFile('html');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=">
</body>
</html>
HTML:
function doGet(e) {
template = HtmlService.createTemplateFromFile('html');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=">
</body>
</html>
您还可以使用HTML5和画布:
<canvas id="myCanvas" width="1" height="1"></canvas>
或JavaScript来创建gif